当命名空间xmlns="http://tempuri.org/BaseSchema"
不存在时,以下XSLT可以完美地从给定的XML中选择节点。
问题:当XML中存在名称空间xmlns="http://tempuri.org/BaseSchema"
时,就像真正的问题一样,XSLT选择XML中的所有内容,而不是XSLT中提到的节点
无法修改输入文件以删除命名空间。有谁知道如何忽略或抑制名称空间的影响。
XML
<event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/BaseSchema" >
<name>Pancake</name>
<categories>
<category>community</category>
</categories>
<venue>
<name>fatzcafe</name>
<city>NYC</city>
<venue_type>
<name>Lounge</name>
<cuisine>Thai</cuisine>
</venue_type>
</venue>
</event>
XSLT
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/BaseSchema">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="/event">
<xsl:apply-templates select="venue/venue_type"/>
</xsl:template>
<xsl:template match="/venue_type">
<xsl:value-of select="name" />
<xsl:value-of select="cuisine" />
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
是的有点在XSLT 1.0中真的很无聊......你必须明确地将你的命名空间绑定到一个前缀,并在你的templates match=
和{{1}的XPath中使用它}} ...
以下是重构的XSLT应该是什么样的:
apply-templates select=