将null值替换为合适的值

时间:2012-08-21 09:24:36

标签: soap wso2esb

我有以下肥皂回应。现在我想用合适的值替换null值。我怎样才能实现它?

       <?xml version='1.0' encoding='utf-8'?>
            <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soapenvelope">
                  <soapenv:Body>
                    <Entries xmlns="http://ws.wso2.org/dataservice">
                       <Entry>
                             <empId>xxx</empId>
                             <empName>yyy</empName>
                             <allocatedDesk>null</allocatedDesk>
                       </Entry>
                    </Entries>
                   </soapenv:Body>
            </soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

您可以使用XSLT替换“null”:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xpath-default-namespace="http://ws.wso2.org/dataservice" version="2.0">
    <xsl:output method="xml" encoding="utf-8" indent="yes"/>

    <xsl:template match="/soapenv:*">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="allocatedDesk[text()='null']">
        <xsl:copy>
            <xsl:value-of select="'YOUR DESIRED TEXT'"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*|node()|@*">
        <!-- copy all elements -->
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

xslt介体用于在WSO2中的MessageContext上应用XSLT。查看文档: http://wso2.org/project/esb/java/3.0.1/docs/mediators/xslt.html