469,275 Members | 1,620 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

variable in xslt

hi friends

i am new user.

i am in the process of collecting the main content and number of title from the input XML with XSLT.
I have doubt in variable increament. how to increamtent variable ?

this is my xml:

Expand|Select|Wrap|Line Numbers
  1. <chunk-meta><title km="Pt.Ttl">PT</title></chunk-meta>
  2. <chunk-meta><title km="At.Ttl">no need</title></chunk-meta>
  3. <float><meta><title km="Ch.Ttl">CT</title></meta></float>
  4. <float><meta><title km="N.Ttl">no need</title></meta></float>
  5. <float-meta><meta><title km="H1.Ttl">HT</title></meta></float-meta>
i expect output to be like this:

Expand|Select|Wrap|Line Numbers
  1. <title km="Pt.Ttl">PT</title><no>1</no>
  2. <title km="Ch.Ttl">CT</title><no>2</no>
  3. <title km="H1.Ttl">HT</title><no>3</no>


this is my xslt:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="xml"/>
  4. <xsl:template match="/">
  5. <xsl:variable name="a" select="1"/>
  6. <xsl:for-each select="//">
  7. <xsl:if test="title/@km[contains(.,'Pt.T')]">
  8. <xsl:copy-of select="title"/><no><xsl:copy-of select="$a"/></xsl:if>
  9. <xsl:if test="title/@km[contains(.,'Ch.Ttl')]"><xsl:variable name="b" select="$a+1"/>
  10. <xsl:copy-of select="title"/><no><xsl:copy-of select="$b"/></xsl:if>
  11. <xsl:if test="title/@km[contains(.,'H1.Ttl')]">
  12. <xsl:variable name="c" select="$b+1"/><xsl:copy-of select="title"/><no><xsl:copy-of select="$c"/></xsl:if>
  13. </xsl:for-each>
  14. </xsl:template>
  15. </xsl:stylesheet>
thanks in adv

saran
Dec 10 '07 #1
0 854

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Son KwonNam | last post: by
4 posts views Thread by Son KwonNam | last post: by
4 posts views Thread by Frederik Sørensen | last post: by
2 posts views Thread by Jon Martin Solaas | last post: by
4 posts views Thread by Cathie | last post: by
2 posts views Thread by Darrel | last post: by
2 posts views Thread by 张韡武 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.