Xslt xsl:match和xsl:apply在同一父级中
我有以下xml结构(在实际示例中,它要长得多,而且很复杂)Xslt xsl:match和xsl:apply在同一父级中,xslt,xpath,Xslt,Xpath,我有以下xml结构(在实际示例中,它要长得多,而且很复杂) ... 我想创建一个模板,如 <xsl:template match="node1" mode="node1"> <img alt="" src="{child1}" /> ... ... </xsl:template> ... ... 并将此模板应用于其他类似的模板 <xsl:template match="anotherNode"&
...
我想创建一个模板,如
<xsl:template match="node1" mode="node1">
<img alt="" src="{child1}" />
...
...
</xsl:template>
...
...
并将此模板应用于其他类似的模板
<xsl:template match="anotherNode">
<xsl:apply-templates select="node1" mode="node1" />
</xsl:template>
如果node1标记有父项,这将很容易做到,但如果它没有父项,我不知道如何匹配和应用模板 您需要在中使用,(。
)
文档中的所有元素都有父元素(请参见)使用:
<xsl:template match="anotherNode">
<xsl:apply-templates select="/*/node1" mode="node1" />
</xsl:template>
<xsl:template match="anotherNode">
<xsl:apply-templates select="../node1" mode="node1" />
</xsl:template>
或者:
<xsl:template match="anotherNode">
<xsl:apply-templates select="/*/node1" mode="node1" />
</xsl:template>
<xsl:template match="anotherNode">
<xsl:apply-templates select="../node1" mode="node1" />
</xsl:template>
发布的输入格式甚至不正确(在根元素的开始标记中键入“docuemnt”),缩进也不清楚,但只要
另一个节点
元素和节点1
元素是同级的,您就可以这样做
<xsl:template match="anotherNode">
<xsl:apply-templates select="preceding-sibling::node1" mode="node1"/>
</xsl:template>
在您的示例中,node1确实有一个父元素--文档
元素。所有元素都有父元素。我知道,但如果我选择文档标记,模板输出所有内容,而不是我需要的内容。这是我的错,我的xml结构更复杂,现在我看到它工作了