尝试第一
我有一个页面,它通过SOAP从web服务中检索响应。我试图将XSL转换应用于响应,但是,我遇到了一个问题,因为嵌套标记包含唯一的“xmlns”属性。
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetPartA xmlns="http://obfuscated.url.com/">
<GetPartB>
<Status>Ok</Status>
</GetPartB>
</GetPartA >
</soap:Body>
</soap:Envelope>从我在网上收集的内容来看,解决方案涉及在xsl文件中声明名称空间,并使用这个名称空间来精确选择,因为包含xmlns标记的元素与不包含xmlns标记的元素不一样。很好,但还是不起作用。
<xsl:stylesheet
xmlns:np="http://obfuscated.url.com/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/">
<xsl:value-of select="soap:Envelope/soap:Body/np:GetPartA/GetPartB/Status"/>
</xsl:template>
</xsl:stylesheet>调试信息
下面的组合工作,以更准确地指出问题。
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetPartA>
<GetPartB>
<Status>Ok</Status>
</GetPartB>
</GetPartA >
</soap:Body>
</soap:Envelope>上面的说明,这已经修改了。
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/">
<xsl:value-of select="soap:Envelope/soap:Body/GetPartA/GetPartB/Status"/>
</xsl:template>
</xsl:stylesheet>发布于 2016-06-02 21:35:09
你这么做的时候..。
<GetPartA xmlns="http://obfuscated.url.com/">然后声明一个默认名称空间,因此GetPartA及其所有后代都在这个名称空间中。对于名称空间,使用的前缀(本例中没有前缀)不是关键因素,需要在XML和XSLT之间匹配的是命名空间uri (本例中为“http://obfuscated.url.com/”)。但是,所使用的前缀可能有所不同。
不过,在你的第一次尝试中,你其实并不遥远。您只需要在np表达式中使用GetPartB和Status之前的XPath。
试试这个XSLT:
<xsl:stylesheet
xmlns:np="http://obfuscated.url.com/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/">
<xsl:value-of select="soap:Envelope/soap:Body/np:GetPartA/np:GetPartB/np:Status"/>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/37602139
复制相似问题