gpt4 book ai didi

xslt - xpath 表达式中的变量

转载 作者:行者123 更新时间:2023-12-03 17:00:22 24 4
gpt4 key购买 nike

在 xpath 表达式中不能使用 xsl:variables 吗?我确信我的变量具有正确的值。已经尝试过将其作为字符串和数字。第一个可行,但第二个选择所有内容节点,而不仅仅是索引为 4 的节点。

<xsl:apply-templates select="data/contents[4]/content" >
<xsl:apply-templates select="data/contents[$myVariable]/content" >

编辑

    <xsl:variable name="dayOfWeekIndex">    
<xsl:choose>
<xsl:when test="lower-case($dayOfWeek) = 'monday'">
<xsl:value-of select="number(1)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'tuesday'">
<xsl:value-of select="number(2)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'wednesday'">
<xsl:value-of select="number(3)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'thursday'">
<xsl:value-of select="number(4)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'friday'">
<xsl:value-of select="number(5)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'saturday'">
<xsl:value-of select="number(6)" />
</xsl:when>
<xsl:when test="lower-case($dayOfWeek) = 'sunday'">
<xsl:value-of select="number(7)" />
</xsl:when>
</xsl:choose>
</xsl:variable>

最佳答案

显然,如何设置变量或参数很重要,例如与

<xsl:variable name="index" select="4"/>
<xsl:apply-templates select="data/contents[$index]/content"/>

它应该可以工作(即处理第四个内容),

<xsl:variable name="index">4</xsl:variable>
<xsl:apply-templates select="data/contents[$index]/content"/>

它不起作用,因为谓词表达式不是 xs:integer 类型,它是一个非空的节点序列。

关于xslt - xpath 表达式中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15944183/

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