gpt4 book ai didi

xslt - 为什么我不能在 XSL 中获取与应用模板一起使用的参数?

转载 作者:行者123 更新时间:2023-12-04 14:21:29 25 4
gpt4 key购买 nike

我发现不可能让 with-param 与 apply-templates 一起工作。例如,我已经破解了 w3schools 中给出的示例。 .

xsl

<xsl:template match="/">
<xsl:apply-templates>
<xsl:with-param name="test" select="'has this parameter been passed?'"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="cd">
<xsl:param name="test"></xsl:param>
parameter:
<xsl:value-of select="$test"></xsl:value-of>
</xsl:template>

xml
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>

(希望如此)您会看到 test 参数没有被传递到 cd 模板。我可以在使用 call-template 时让它工作,但不是 apply-templates。这是怎么回事?我正在使用 XSL 1.0。请忽略我传递的是硬编码参数这一事实——这只是一个例子。

最佳答案

嗯……有趣……我使用 XslTransform 失败了和 XslCompiledTransform在 .NET 中 - 但它看起来应该可以工作......好奇......

更新 问题似乎是 比赛;尝试

<xsl:template match="/catalog"> <!-- CHANGE HERE --> 
<xsl:apply-templates>
<xsl:with-param name="test" select="'has this parameter been passed?'"/>
</xsl:apply-templates>
</xsl:template>

然后这对我有用,没有任何其他变化。不同之处在于您匹配了根节点。当您执行“应用模板”时,它首先级联到目录(带参数),然后是 cd(不带参数)。要得到你想要的东西,你需要从目录开始。您可以通过添加 <xsl:vaue-of select="name()"/> 来查看这一点。匹配,然后尝试将其作为“/”和“/catalog”。

关于xslt - 为什么我不能在 XSL 中获取与应用模板一起使用的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/590157/

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