Subject: RE: Re: [xsl] Count the node from zero instead of one From: Rashi Bhardwaj <rashi.bhardwaj@xxxxxxxxx> Date: Sat, 27 Nov 2010 20:36:47 +0530 |
Hello Mukul, I am sorry mention in my query that I can use xslt 1.0. Sincere apologies for the same. Is it possible to perform the same function with xslt 1.0? Please let me know....Cant we take the value in a variable instead of element ''position''? Thanks, Rashi > Date: Fri, 26 Nov 2010 14:48:10 +0530 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> > Subject: Re: [xsl] Count the node from zero instead of one. > Message-ID: <AANLkTinxEzwQXzb7PgOBGoy+LSEKyScE1WJUwpKqRAVX@xxxxxxxxxxxxxx> > > In XSLT 2.0 you may try to do something like below, > > <xs:function name=3D"func:myNumber" as=3D"xs:positiveInteger"> > <xsl:param name=3D"nodePattern" as=3D"node()*" /> > > <xsl:variable name=3D"num" as=3D"xs:positiveInteger"> > <xsl:number count=3D"$nodePattern"/> > </xsl:variable> > <xsl:sequence select=3D"$num - 1" /> > </xs:function> > > and replace following in your code: > > <xsl:element name=3D"position"> > <xsl:number count=3D"*"/> > <xsl:text>,</xsl:text> > </xsl:element> > > with > > <position> > <xsl:value-of select=3D"func:myNumber(*)" /> > <xsl:text>,</xsl:text> > </position> > > you would have to bind the function namespace prefix "func:" to an > appropriate URI. > > This is not tested. > > On Fri, Nov 26, 2010 at 12:38 PM, Rashi Bhardwaj > <rashi.bhardwaj@xxxxxxxxx> wrote: >> HI All, >> >> I m counting the node position from this logic in the below sample xml >> >> xml: >> >> <test> >> <a> >> <b name =3D'1'></b> >> <b name =3D'2'></b> >> <b name =3D'3'> >> <c>aaa</c> >> </b> >> <b name =3D'4'> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0<c>bbb</c> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0<c>ccc</c> >> </b> >> <b name =3D'4'> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0<c>dddd</c> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0<c>eeee</c> >> </b> >> </a> >> <a> >> <b name =3D'1'></b> >> <b name =3D'2'> >> <c>fffff</c> >> </b> >> <b name =3D'3'></b> >> <b name =3D'4'> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0<c>gggg</c> >> </b> >> </a> >> </test> >> >> <xsl:template name=3D"CountNode"> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<xsl:param name=3D= > "node" >> select=3D"//b[c[preceding-sibling::c]][not(@name >> =3Dpreceding::b[child::c]/@name)]/@name"/> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<xsl:for-each sele= > ct=3D"$node"> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= > =A0 =C2=A0<xsl:element name=3D"position"> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= > =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<xsl:number count=3D"*"/> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= > =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<xsl:text>,</xsl:text> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= > =A0 =C2=A0</xsl:element> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= > =A0 =C2=A0<xsl:if test=3D"position()!=3Dlast()"/> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</xsl:for-each> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0</xsl:template> >> >> it gives the result 3,4,2,....I want it should count from zero instead >> of one and the result shld be 2,3,1.or it can print the result by >> subracing 1 from it like 3-1=3D2. >> >> Please suggest some thing... >> >> Thanks.... >> Rashi > > --=20 > Regards, > Mukul Gandhi -- Rashi Bhardwaj
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] java heap management for , David Carlisle | Thread | Re: Re: [xsl] Count the node from z, Mukul Gandhi |
Re: [xsl] java heap management for , David Carlisle | Date | Re: Re: [xsl] Count the node from z, Mukul Gandhi |
Month |