我正在尝试使用 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/