[英]How to change the root of <xsl:for-each > dynamically in xslt file
I want to change the root of <xsl:for-each>
dynamically. 我想动态更改
<xsl:for-each>
的根。 Actually I used nested loop. 实际上,我使用了嵌套循环。 Based on the outer loop I want to change the root of inner loop.
基于外部循环,我想更改内部循环的根。 For that I write the following code but I am not able to do it.
为此,我编写了以下代码,但无法执行。
outer loop start then variable that hold root 外循环开始,然后保持根的变量
<xsl:variable name="cdtitle">
<xsl:value-of select="/root/Data/AppNameEncrpt"/>
</xsl:variable>
inner loop
<xsl:for-each select="msxsl:node-set($cdtitle)">
..
</xsl:for-each>
If I pass the static value of msxsl:node-set($cdtitle)
then it work but when I pass it as a varible in root it not work 如果我传递了
msxsl:node-set($cdtitle)
的静态值,则它可以工作,但是当我将其作为变量传递给root时,它不起作用
How can achieve the same. 怎么能达到同样的效果。 Can anyone help me.
谁能帮我。
In XSLT (as in any functional language), variables are immutable. 在XSLT中(与任何功能语言一样),变量是不可变的。 However, inside a "loop" (which technically is not a loop) you can set the variable to anything that is in the context of that loop.
但是,在“循环”(从技术上讲不是循环)内部,可以将变量设置为该循环上下文中的任何变量。 Since you didn't show any input XML, I am guessing to what you want to achieve, but there's always a (simple) way.
由于您没有显示任何输入XML,因此我在猜测要实现的目标,但是总有一种(简单的)方法。
Suppose you have this variable: 假设您有以下变量:
<xsl:variable name="cdtitles" select="/data/cds/title" />
It will hold all cd titles. 它将保留所有cd标题。 Now I can do:
现在我可以做:
<xsl:for-each select="$cdtitles">
<xsl:variable name="cdtitle" select="." />
<!-- do something with the title, var changes with each title -->
</xsl:for-each>
Have a look at XSLT: Getting started , it will help you understand these and other principles of the language. 看看XSLT:入门 ,它将帮助您理解语言的这些原则和其他原则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.