html - 在 xslt 文件中获取 "prefix ' soap' is not defined"

标签 html xml xslt

我正在尝试使用 xml 数据(来自 Web 服务的响应)转换字符串。我试图通过获取名称来简单地开始:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
      <table>
        <tr>
          <th>Name</th>
        </tr>
        <xsl:for-each select="soap:Envelope/soap:Body/ABRSearchByABNResponse/ABRPayloadSearchResults/response/legalName/">
          <tr>
            <td>
              <xsl:value-of select="givenName"/>
            </td>      
          </tr>   
      </xsl:for-each>

      </table>
    </xsl:template>
</xsl:stylesheet>

但是,我收到“未定义前缀‘soap’”,我该如何解决这个问题? 谢谢。

最佳答案

在 XSLT 中,XPath 表达式中使用的任何 namespace 前缀都必须在相应的 namespace 声明中定义。

您的代码不是这种情况,因此是错误。

解决方案:

声明 soap 命名空间:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     
 xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
 xmlns:soap="http://soap/envelope/"
>

关于html - 在 xslt 文件中获取 "prefix ' soap' is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4794432/

相关文章:

html - 我将如何使用::after 在我的按钮上制作箭头?

c# - 我如何定义我的类,以便可以在运行时指定节点的 XmlAttribute 文本(不是它的值),而无需自定义序列化程序?

java - 当使用架构验证无效 XML 时,为什么我没有得到异常?

python - 使用 minidom 从 XML 节点中提取文本

xslt 1.0 如何测试数字

java - 是否可以在 xslt 中格式化一个大的小数日期

css - 使渐变适应浏览器高度

javascript - Angular 一个独立的 CSS block

xml - 重命名元素并保留属性

html - 使用图像选择模板