分配给 <xsl:variable>解除后 [英] Assign to <xsl:variable> after thedecleration
问题描述
我正在使用以下方法为变量赋值.
I am using the below way to assign value to a variable.
<xsl:variable name="NewValue">
<xsl:value-of select="normalize-space(//root/id/amount)"/>
</xsl:variable>
赋值后,我想为同一个变量分配新值.像这样:-
After the assignment I want to assign new value to the same variable. Like this:-
<xsl:variable name="NewValue" select="normalize-space(//root/id/amountnew)">
有什么办法吗?
这是我拥有的 XML 示例:
Here the sample of XML that I have:
<VolLien>
<Vest_DocType>SDD</Vest_DocType>
<Vest_Instrument>395072</Vest_Instrument>
<Vest_OfOfficialEntity>eee</Vest_OfOfficialEntity>
<Vest_RecDate>12/24/2009</Vest_RecDate>
<Vest_Grantee1>abc dd</Vest_Grantee1>
<Vest_Grantor1>sss</Vest_Grantor1>
<Vest_RejectCode />
<Vest_RejectReason />
<Vest_ImageNum> </Vest_ImageNum>
</VolLien>
我的问题是我需要获取特定
的最新
(比如SDD)然后我需要在任何日期搜索xml在
之前(相同的 SDD).
My problem is I need to get latest <Vest_RecDate>
of particular <Vest_DocType>
(say SDD) And then I need to search across the xml any date which is before <Vest_RecDate>
of this(same SDD).
如果然后单独提出该特定部分(
)并再次更新.如果我可以重新分配,我会定位节点并获取与之相关的值.现在我正在使用另一个循环来执行此操作.如果有什么,我可以避免 extrs 循环.
If then raise that particular section(<VolLien>
) alone and again latest. If I could have reassignment I would position of the node and get the values associated to that. Now I am doing this using another loop. If something is there I can avoid extrs loops.
推荐答案
没有.XSLT 变量是只读的.它们不能被多次分配.
No. XSLT variables are read-only. They cannot be assigned multiple times.
XSLT 不是像 PHP 这样的命令式编程语言.重新分配变量既不可能也没有必要.
XSLT is not an imperative programming language like, say, PHP. Reassigning variables is both impossible and unnecessary.
根据您的评论:
我的问题是我需要获取最新的特定
(比如 SDD),然后我需要在 xml 中搜索
My problem is I need to get latest of particular
<Vest_DocType>
(say SDD) and then I need to search across the xml any date which is before<Vest_RecDate>
of this (same SDD).
这是可以为您执行此操作的 XSLT 代码段:
here is an XSLT snippet that can do this for you:
<!-- a key to retrieve all <VolLien> nodes of a particular DocType -->
<xsl:key name="VolLien-by-DocType" match="VolLien" use="Vest_DocType" />
<xsl:template match="/">
<xsl:call-template name="latest-VolLien">
<xsl:with-param name="DocType" select="'SDD'" />
</xsl:call-template>
</xsl:template>
<!-- this template processes specified <VolLien> nodes in the right order -->
<xsl:template name="latest-VolLien">
<xsl:param name="DocType" select="''" />
<xsl:for-each select="key('VolLien-by-DocType', $DocType)">
<!-- sorting is a little complicated because you
use dd/mm/yyyy instead of yyyymmdd -->
<xsl:sort
select="
number(substring(Vest_RecDate, 7, 4)) +
number(substring(Vest_RecDate, 4, 2)) +
number(substring(Vest_RecDate, 1, 2))
"
data-type="number"
/>
<!-- do something with last <VolLien> (in date order) -->
<xsl:if test="position() = last()">
<xsl:apply-templates select="." />
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="VolLien">
<!-- this template will actually process the nodes,
do whatever you want here -->
</xsl:template>
这篇关于分配给 <xsl:variable>解除后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!