我有来自webservice的这个xml输出:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<FLNewIndividualID xmlns="http://www.test.com/wsdl/TTypes">
<ObjectType>C1</ObjectType>
<ObjectReference>101000216193</ObjectReference>
<ObjectReference xsi:nil="true"/>
<ObjectReference xsi:nil="true"/>
</FLNewIndividualID>
</soapenv:Body>
</soapenv:Envelope>
我正在尝试提取ObjectType和ObjectReference 所以我有这个XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:nsl="http://www.test.com/wsdl/TTypes"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/env:Envelope/env:Body/nsl:FLNewIndividualID">
<xsl:value-of select="ObjectType"/>-<xsl:value-of select="ObjectReference"/>
</xsl:template>
</xsl:stylesheet>
我得到了
<?xml version="1.0" encoding="utf-8"?>
结果是如果我在结果中添加一个空白属性xmlns =“” 例如
<ObjectType xmlns="">C1</ObjectType>
<ObjectReference xmlns="">101000216193</ObjectReference>
然后它起作用了,我得到了:
<?xml version="1.0" encoding="utf-8"?>
C1-101000216193
有什么想法吗?我无法更改XML输出。
答案 0 :(得分:1)
<FLNewIndividualID>
具有默认的命名空间集,因此其子级继承该命名空间。
尝试
<xsl:value-of select="nsl:ObjectType" />
<xsl:text>-</xsl:text>
<xsl:value-of select="nsl:ObjectReference" />
使用exclude-result-prefixes
也是个好主意。
例如:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:nsl="http://www.test.com/wsdl/TTypes"
exclude-result-prefixes="env nsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="nsl:FLNewIndividualID">
<xsl:value-of select="concat(nsl:ObjectType, '-', nsl:ObjectReference)" />
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
(当然这个样本不能生成格式良好的XML)