Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Count occurence and add the index in xsl

From: "Geert Josten" <geert.josten@----------->
To:
Date: 10/4/2006 2:54:00 PM
Hi,

Why not use apply-templates instead of call-templates. It is perfectly
legal to pass parameters to apply-templates as wel.

About the index number, you might want to try:
count(preceding-sibling::*[name() = name(current())]).

Though, if it is an option to add an index number to ALL id's, you could
use position() instead. Probably a lot quicker as well..

Kind regards,
Geert


>


Drs. G.P.H. Josten
Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl
KvK 27164984


De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit
bericht kunnen geen rechten worden ontleend.


> Van: Arulraj [mailto:p_arulraj@xxxxxxxxx]
> Verzonden: woensdag 4 oktober 2006 15:53
> Aan: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Onderwerp: [xsl] Count occurence and add the index in xsl
>
> 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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent