[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Count occurence and add the index in xsl

Subject: Count occurence and add the index in xsl
From: Arulraj <p_arulraj@xxxxxxxxx>
Date: Wed, 4 Oct 2006 06:52:56 -0700 (PDT)
xsl template match count occurence
Hello all,

i want to get the index in the output.

Input XML looks like the
following
----------------------------------------------------
<?xml
version="1.0" encoding="UTF-8"?>
<Zeitraum>
    <Years
format="yyyy">2005</Years>
    <Days>21</Days>
    <Weeks>22</Weeks>
<Date>
        <Day>10</Day>
        <Month>02</Month>
<Year>2006</Year>
    </Date>
    <test> </test>
    <test></test>
    <Date>
<Day>10</Day>
        <Month>02</Month>
        <Year>2006</Year>
    </Date>
<test></test>
</Zeitraum>

I have the following xsl
---------------------------------

    <xsl:output method="xml" indent="yes"/>
<xsl:template match="/*">
        <tree id="0">
            <xsl:call-template
name="TreeXML">
                <xsl:with-param name="nameTmp"
select="name()"/>
            </xsl:call-template>
        </tree>
</xsl:template>
    <xsl:template name="TreeXML">
        <xsl:param
name="nameTmp"/>
        <item id="{$nameTmp}" text="{name()}">
<xsl:for-each select="*">
                <xsl:call-template name="TreeXML">
<xsl:with-param name="nameTmp" select="concat($nameTmp,'_',name())"/>
</xsl:call-template>
            </xsl:for-each>
        </item>
</xsl:template>
</xsl:stylesheet>

I got the following output
------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<tree id="0"><item id="Zeitraum" text="Zeitraum"><item id="Zeitraum_Years"
text="Years"/>
      <item id="Zeitraum_Days" text="Days"/>
      <item
id="Zeitraum_Weeks" text="Weeks"/>
      <item id="Zeitraum_Date"
text="Date"><item id="Zeitraum_Date_Day" text="Day"/>
         <item
id="Zeitraum_Date_Month" text="Month"/>
         <item id="Zeitraum_Date_Year"
text="Year"/>
      </item>
      <item id="Zeitraum_test" text="test"/>
<item id="Zeitraum_test" text="test"/>
      <item id="Zeitraum_Date"
text="Date"><item id="Zeitraum_Date_Day" text="Day"/>
         <item
id="Zeitraum_Date_Month" text="Month"/>
         <item id="Zeitraum_Date_Year"
text="Year"/>
      </item>
      <item id="Zeitraum_test" text="test"/>
</item>
</tree>

My Expected output is
-----------------------------------------
<?xml version="1.0"
encoding="utf-8"?>
<tree id="0">
    <item id="Zeitraum" text="Zeitraum">
<item id="Zeitraum_Years" text="Years"/>
        <item id="Zeitraum_Days"
text="Days"/>
        <item id="Zeitraum_Weeks" text="Weeks"/>
        <item
id="Zeitraum_Date_0" text="Date">
            <item id="Zeitraum_Date_0_Day"
text="Day"/>
            <item id="Zeitraum_Date_0_Month" text="Month"/>
<item id="Zeitraum_Date_0_Year" text="Year"/>
        </item>
        <item
id="Zeitraum_test_0" text="test"/>
        <item id="Zeitraum_test_1"
text="test"/>
        <item id="Zeitraum_Date_1" text="Date">
<item id="Zeitraum_Date_1_Day" text="Day"/>
            <item
id="Zeitraum_Date_1_Month" text="Month"/>
            <item
id="Zeitraum_Date_1_Year" text="Year"/>
        </item>
        <item
id="Zeitraum_test_2" text="test"/>
    </item>
</tree>

Question:
I want to
add the index in the id attribute. suppose if the element is repeated i want
to add that count index. Only for the repeated element i want to get the index
How to do this?

Any help
regards,
raj

Current Thread

Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.