我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)
但是,我得到"前缀'肥皂'没有定义",我该如何解决这个问题?谢谢.
在XSLT中,必须在相应的名称空间声明中定义XPath表达式中使用的任何名称空间前缀.
您的代码不是这种情况,因此也就是错误.
方案:
声明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/"
>
Run Code Online (Sandbox Code Playgroud)