【问题标题】:xslt and SOAP namespace: how to addxslt 和 SOAP 命名空间:如何添加
【发布时间】:2013-04-06 15:03:16
【问题描述】:

我有这个基本的 SOAP 响应:

<?xml version="1.0" encoding="WINDOWS-1252" standalone="yes"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body xmlns="http://www.xxx.com/dotnet/types/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <a>
            <b>
                   <c>
                    c-value
                   </c>
                       b-value
            </b>
                a-value
        </a>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我只想输出c节点的值:c-value。

我不明白为什么这个 xsl 不起作用:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
>
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
 <xsl:value-of select="//c"/>
</xsl:template>
</xsl:stylesheet>

似乎问题出在&lt;SOAP-ENV:Body xmlns="http://www.xxx.com/dotnet/types/" 的名称空间中 如果我删除它,它会起作用。

我想我应该更改 select="//c" 中的 xpath 或在 xls 中的某处添加所需的命名空间,但我做错了!

【问题讨论】:

  • 是的确实...经过数小时的搜索和试验,链接在编写问题时出现了,这就是为什么我将它包含在我的答案中...这是相同的情况,但适用于 SOAP ,很容易被忽略。但我同意,这是重复的

标签: xslt soap xml-namespaces


【解决方案1】:

好的,这个链接很有帮助:How to 'select' from XML with namespaces?

我添加了这样的命名空间:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xxx="http://www.xxx.com/dotnet/types/"
>
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
 <xsl:value-of select="//xxx:c"/>
</xsl:template>
</xsl:stylesheet>

首先将 xmlns:xxx 添加到 xlst,然后 XPath 变为 //xxx:c。

用 SO 写问题,解决问题...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 2013-07-24
    • 2011-09-09
    • 2011-02-10
    相关资源
    最近更新 更多