【发布时间】:2016-01-17 19:00:27
【问题描述】:
当命名空间 xmlns="http://tempuri.org/BaseSchema" 不存在时,以下 XSLT 完美地从给定 XML 中选择节点。
问题:当名称空间xmlns="http://tempuri.org/BaseSchema" 出现在 XML 中时,就像真正的问题一样,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>
【问题讨论】: