我有这个简化的 xml:
<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>
<c>
<d>1</d>
<e>2</e>
</c>
</b>
<f>
<g>3</g>
</f>
</a>
这是我尝试应用的 xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="a">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="b">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="c">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="d">
</xsl:template>
</xsl:stylesheet>
当我应用此表时,我得到输出 2 3,它们是剩余的文本节点。我读过有关内置模板的信息,如果找不到匹配的模板,则会应用这些内置模板,但在这种情况下,它应该找到模板吗?
到底是怎么回事?
Edit:
在这种情况下,我希望看不到任何内容,因为模板是空的。但我得到了 2 3 。
当你这样做时<xsl:template match="d">
,你告诉处理器忽略下面的所有节点<d>
.
所有其他节点均按默认规则进行处理,包括text()
一、就是打印文本。
这就是为什么您看到的是 23,而不是 1。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)