我有一个xml文件,让我们说:
<parent>
<notimportant1>
</notimportant1>.
<notimportant2>
</notimportant2>.
....
<child>
<grandchild>.
....
</grandchild>
<grandchild>
....
</grandchild>.
....
<notimportant3>
</notimportant3>
</child>
<parent>
Run Code Online (Sandbox Code Playgroud)
还有xsl文件:
<xsl:template match="parent">.
...
...
<xsl:for-each select="child">.
<xsl:for-each select="grandchild">
...
</xsl:for-each>.
</xsl:for-each>
....
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
现在,我必须创建新xsl文件,该文件只能导入/包含此文件xsl.
是否可以覆盖此for-each行为,以便我只能显示一些预定义的文本/链接?
我无法修改现有的xsl,我想使用模板中的其他所有内容 - 不能只定义具有更高优先级的新内容.
您可以重新设计原始样式表xsl:apply-templates而不是使用xsl:for-each.像这样的东西:
<xsl:template match="parent">
...
...
<xsl:apply-templates select="child"/>
....
</xsl:template>
<xsl:template match="child">
<xsl:apply-templates select="grandchild"/>
</xsl:template>
<xsl:template match="grandchild">
...
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
然后,当您在另一个样式表中导入此样式表时,您可以覆盖匹配的模板child或grandchild您希望的模板.