为什么XSLT转换不是预期的输出
环境:XSLT 1.0 预期输出:仅级别2元素的文本节点 实际输出:级别1和级别2文本输出 xsl为什么XSLT转换不是预期的输出,xslt,xslt-1.0,Xslt,Xslt 1.0,环境:XSLT 1.0 预期输出:仅级别2元素的文本节点 实际输出:级别1和级别2文本输出 xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/*">
<xsl:apply-templates select="/data/section1" />
</xsl:template>
<xsl:template match="level2">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="SelectingAndMatching.xslt"?>
<data>
<section1>
<level1>hello world 1</level1>
<level2>unlocked achievement level 2</level2>
</section1>
<section2>
<product1></product1>
<product2></product2>
<product3></product3>
</section2>
</data>
xml
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/*">
<xsl:apply-templates select="/data/section1" />
</xsl:template>
<xsl:template match="level2">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="SelectingAndMatching.xslt"?>
<data>
<section1>
<level1>hello world 1</level1>
<level2>unlocked achievement level 2</level2>
</section1>
<section2>
<product1></product1>
<product2></product2>
<product3></product3>
</section2>
</data>
你好,世界1
解锁成就等级2
处理从没有模板的文档节点/
开始,因此使用其中一个进行
,即处理所有子节点,在您的情况下,这些子节点是与模板匹配的数据元素match=“/*”
处理您没有模板的/data/section1
,因此使用内置的
,即处理section1
的所有子节点,其中包括您有模板的level1
元素,以便使用内置的来处理所有子节点,对于这些文本节点,您同样没有模板,而内置的文本节点将它们复制到输出。处理从没有模板的文档节点开始,因此使用了其中一个,即,处理所有子节点,在您的情况下,这些子节点是与您的模板匹配的数据元素匹配=“/*”
,该子节点处理没有模板的/data/section1
,因此使用内置节点,即,处理section1
的所有子节点,该子节点包括您拥有模板的level1
元素,因此使用内置节点处理所有子节点,同样,对于这些文本节点,您没有模板,内置的文本节点将它们复制到输出。section1有level1和level2元素,我只需要level2,所以我的选择可能如下:select=“/data/section1/level2”
Yes,在这种简单的情况下,您已经有了
,最好将其更改为
。另一个解决方案是确保level1
元素不会产生任何输出,例如
。虽然section1有level1和level2元素,但我只想要level2,所以我的选择可能应该是这样的:select=“/data/section1/level2”
Yes,在这种简单的情况下,您已经有了
,最好将其更改为
。另一个解决方案是确保level1
元素不会产生任何输出,例如
。