【发布时间】:2011-12-09 08:32:41
【问题描述】:
我有以下 xml 文件:
<DataConfiguration
xmlns="http://www.mysite.com/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mysite.com/namespace/DataConfiguration.xsd">
<rule>
<if>
...
</if>
<then>
...
</then>
</rule>
</DataConfiguration>
我想使用以下 xslt 解析:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doc="http://www.mysite.com/namespace"
exclude-result-prefixes="xsi">
<xsl:output omit-xml-declaration="yes"/>
<xsl:output method="text"/>
<xsl:template match = "/">
<xsl:for-each select="//rule">
<xsl:for-each select="if/*">
...
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
xslt 按预期工作,但是当我将 xmlns 属性添加到 xml 的顶部元素时,它无法找到 xml 元素。我在这个网站上看到了一些相关的问题,但仍然不知道如何解决我的具体问题。我尝试按照建议的here 将 doc: 添加到选择中,但没有帮助。也许是因为我正在使用 // ?还有其他方法可以进行这些查询吗?
还有其他解决方法的建议吗?
【问题讨论】:
标签: xml xslt namespaces transform