gpt4 book ai didi

xslt - 如何在 xsl :apply-template? 中测试匹配

转载 作者:行者123 更新时间:2023-12-04 22:47:01 26 4
gpt4 key购买 nike

在我的第二个 xsl:template 匹配中,如何测试匹配模式?例如,如果匹配模式是标题,我想输出不同的值?

  <xsl:template match="secondary-content">
<div class="secondary">
<xsl:apply-templates select="title" />
<xsl:apply-templates select="block/content | content" />
</div>
</xsl:template>
<xsl:template match="title|content|block/content">
<xsl:copy-of select="node()" />
</xsl:template>

最佳答案

好问题,+1。

在第二个模板中,使用这个测试表达式:

test="self::title"

或者
test="local-name() = 'title'"

例如,您可以使用
<xsl:choose>
<xsl:when test="self::title">
<someThing>foo</someThing>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="node()" />
</xsl:otherwise>
</xsl:choose>

关于xslt - 如何在 xsl :apply-template? 中测试匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7151640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com