一个XSL选择=“子::节点”问题
问题描述:
有,我无法理解,并会感激求助的问题:一个XSL选择=“子::节点”问题
我有一个XML文件,它看起来像这样
<xml>
<parent>
<child_node>1</child_node>
<child_node>2</child_node>
<child_node>3</child_node>
</parent>
<parent>
<child_node>4</child_node>
</parent>
</xml>
而一个XSL模板:
<xsl:template name="template">
<xsl:param name="top_node"/>
<xsl:for-each select="$top_node/child::child_node">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
被称为与<xsl:with-param name="top_node" select="xml/parent">
我预计这将返回只有子节点是单个父节点的子节点,如图所示here,但它会返回所有子节点。我在这里错过了什么?
答
很难弄清楚这个XSLT的最终目的是什么,没有看到更多的,但你得到这种现象的原因是,路径xml/parent
选择相匹配的路径,而不仅仅是所有节点第一。如果你想将它应用到某些其他一个
<xsl:with-param name="top_node" select="xml/parent[1]">
:如果你想将它应用到只是第一个,你能做到这一点
<xsl:with-param name="top_node" select="xml/parent[2]">
<xsl:with-param name="top_node" select="xml/parent[3]">
etc.