不能重新分配一個值,XSLT變量從
<xsl:for-each
有條件
我的XML無法從for-each循環有條件
<R>
<A id="a">
<S id="a111">1</S>
<S id="a222">2</S>
<S id="a333">3
<S id="a3331">3.1</S>
<S id="a3332">3.2</S>
<S id="a3333">3.3</S>
</S>
<S id="a444">4</S>
<S id="a555">5</S>
<S id="a666">6</S>
</A>
<A id="x">
<S id="x111">1</S>
<S id="x222">2</S>
<S id="x333">3
<S id="x3331">3.1</S>
<S id="x3332">3.2</S>
<S id="x3333">3.3</S>
</S>
<S id="x444">4</S>
<S id="x555">5</S>
<S id="x666">6</S>
</A>
</R>
重新分配一個值,XSLT變量,或者我可以退出,或者我可以退出
我的XSLT
<select id ="S" name="SList">
<option>
<xsl:attribute name="value"></xsl:attribute> Please Select S
</option>
<xsl:for-each select="A[id='x']//S">
<xsl:if test="'x3333'= @id">
<xsl:variable name="currentS" select="true()"/>
</xsl:if>
<xsl:if test="'x3333'!= @id">
<xsl:variable name="currentS" select="false()"/>
</xsl:if>
<xsl:if test="@currentS = false()">
<option>
<xsl:if test="@id = 'x3333'">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="Text"/>
</option>
</xsl:if>
</xsl:for-each>
我試圖創建一個下拉列表,我需要在列表中包含S
項目。我通過當前位置(當前位置S
,在此示例中爲x3333
),當前編號爲A
。我想在最近的A
元素中只獲得S
元素的列表。
在這個例子中,因爲我現在的S
是x3333
和A
ID是x
我只需要x111
,x222
,x333
,x3331
,x3332
是在列表中。這意味着我需要消除這些
<S id="x444">4</S>,
<S id="x555">5</S>,
<S id="x666">6</S>, nodes
從這個代碼
<xsl:for-each select="A[id='x']//S">
我越來越S
元素的列表
在A
其中id='x'
有人建議我一個解決方案嗎?做你想要用XSLT變量做什麼
感謝您回覆@ hr_117,當我嘗試使用此方法訪問變量它說」變量或參數未定義或超出範圍「 –
2013-05-14 13:11:30
請查看更新。 – 2013-05-14 13:17:27
謝謝@ hr_117 ..是的,這是非常好的,適合我的傾斜。謝謝 – 2013-05-14 13:47:19