gpt4 book ai didi

XSLT:我可以全局声明一个变量,然后给它赋值吗

转载 作者:行者123 更新时间:2023-12-03 11:08:01 25 4
gpt4 key购买 nike

我该怎么做才能使此代码正常工作?

<xsl:choose>
<xsl:when test='type = 6'>
<xsl:variable name='title' select='root/info/title' />
</xsl:when>
<xsl:when test='type = 7'>
<xsl:variable name='title' select='root/name' />
</xsl:when>
<xsl:otherwise>
<xsl:variable name='title'>unknown</xsl:variable>
</xsl:otherwise>
</xsl:choose>

<div class='title'>
<xsl:value-of select='$title'/>
</div>

这不起作用,因为当我这样做时 <xsl:value-of select='$title'/> , $title超出范围。我试图添加行 <xsl:variable name='title'/>超出范围,但这也不起作用,因为那时我调用 <xsl:variable name='title' select='root/info/title' />例如,我之前已经设置了这个变量。我应该如何解决这个问题?

最佳答案

您可以在变量的设置中移动选择,如下所示:

<xsl:variable name="title">
<xsl:choose>
<xsl:when test='type=6'>
<xsl:value-of select="root/info/title" />
</xsl:when>
...
</xsl:choose>
</xsl:variable>

<div class='title'>
<xsl:value-of select="$title" />
</div>

关于XSLT:我可以全局声明一个变量,然后给它赋值吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4204996/

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