难道不能在 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>