在清除后分配给<xsl:variable>

Var*_*run 6 xslt xslt-2.0

我使用以下方式为变量赋值.

<xsl:variable name="NewValue">
  <xsl:value-of select="normalize-space(//root/id/amount)"/>
</xsl:variable>
Run Code Online (Sandbox Code Playgroud)

在赋值后,我想为同一个变量赋值.像这样:-

<xsl:variable name="NewValue" select="normalize-space(//root/id/amountnew)">
Run Code Online (Sandbox Code Playgroud)

这有什么办法吗?


这里是我的XML样本:

<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>
Run Code Online (Sandbox Code Playgroud)

我的问题是我需要获得<Vest_RecDate>特定的最新信息<Vest_DocType>(比如SDD)然后我需要在xml之前搜索任何日期<Vest_RecDate>(相同的SDD).

如果然后<VolLien>单独提高该特定部分()再次最新.如果我可以重新分配,我会定位节点并获取与之关联的值.现在我正在使用另一个循环.如果有什么东西我可以避免extrs循环.

Tom*_*lak 8

不,XSLT变量是只读的.它们不能多次分配.

XSLT不是一种命令式的编程语言,比如PHP.重新分配变量既不可能也不必要.


编辑:根据你的评论:

我的问题是我需要获得特定的最新信息<Vest_DocType>(比如SDD),然后我需要在xml之前搜索任何日期<Vest_RecDate>(相同的SDD).

这是一个可以为您执行此操作的XSLT代码段:

<!-- 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>
Run Code Online (Sandbox Code Playgroud)