Link to home
Start Free TrialLog in
Avatar of tesmc
tesmcFlag for United States of America

asked on

XSLT: how to increment number value if attribute present

i have the following input

<xml>
      <Flight ID="F1">
      <Flight ID="F2">
      <Flight ID="F3" AddNew="Yes">
      <Flight ID="F4">
</xml>
      
      

I want my output to read:

<xml>
       <Flight ID="1"/>
      <Flight ID="2"/>
      <Flight ID="4"/>
      <Flight ID="5"/>
</xml>      



I have following xsl .which loops through each @ID and builds the ID by grabbing number after 'F'. And this is ok but I want to increment the number if AddNew="Yes" exists.  



<xsl:variable name="Seg" select="//Flight/@ID"/>


<xsl:for-each select="$Seg">

<xsl:variable name="ID">
  <xsl:value-of select="substring-after(current(), 'F')"/>
</xsl:variable>


<xsl:attribute name="ID" >
<xsl:value-of select="$ID"/>
</xsl:attribute>

.....
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tesmc

ASKER

@Geert Bormans
Yes that worked fine.
can you explain  count(preceding-sibling::Flight[@AddNew = 'Yes']) ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tesmc

ASKER

thank you for your help.