gpt4 book ai didi

xslt - xsl :apply-templates: match not being respected

转载 作者:行者123 更新时间:2023-12-04 06:09:17 28 4
gpt4 key购买 nike

我在使用 xsl:apply-templates 时遇到问题。我正在尝试将模板应用于一个特定标签,但我看到了来自其他标签的文本。一个简单的xml文件:

<?xml version="1.0"?>                                                  

<!-- execute with xsltproc foo.xsl foo.xml -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:output method="text" />

<xsl:template match="/foo">
<xsl:for-each select="bar">
<xsl:value-of select="grill"/>
<xsl:apply-templates match="baz"/>
</xsl:for-each>
</xsl:template>

<xsl:template match="foo">[<xsl:value-of select="." />|http://example.com/<xsl:value-of select="." />]</xsl:template>
</xsl:stylesheet>

输入是:
<?xml version="1.0"?>

<foo>
<bar>
<baz>a <foo>b</foo> c</baz>
<grill>grill</grill>
</bar>
</foo>

输出是:
grill
a [b|http://example.com/b] c
grill

我期待输出是
grill
a [b|http://example.com/b] c

(我暂时不关心间距问题)

我可以通过用 xsl:for-each 包装 xsl:apply-templates 来解决这个问题:
<xsl:for-each select="grill">
<xsl:apply-templates match="grill"/>
</xsl:for-each>

但我真的不喜欢这个解决方案。有没有更好的办法?

最佳答案

属性 match不允许在 xsl:apply-templates 上使用元素。更改 matchselectxsl:apply-templates然后再试一次。

关于xslt - xsl :apply-templates: match not being respected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970529/

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