Subject: RE: [xsl] Problem with generating sequence ids. From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 6 Jul 2005 14:10:42 +0100 |
In XSLT 2.0 try something like <xsl:attribute name="sequence" select=" substring(concat( string-join((for $n in ancestor-or-self::* return format-number(number(@sequence), '000')), ''), '000000000000000000'), 1, 15)"/> Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Lakshmi narayana [mailto:lchintala@xxxxxxxxxxxx] > Sent: 06 July 2005 14:15 > To: XSL (E-mail) > Subject: [xsl] Problem with generating sequence ids. > > > Hi, > I am facing the problem to create the IDs to the elements. See the > following example XML file. > <A1 sequence="1"> > <B1 sequence="3"/> > <B2 sequence="1"> > <C1 sequence="4"></C1> > <C2 sequence="11"> > <D1 sequence="01"/> > </C2> > </B2> > </A1> > > I want the xslt code to get the result as > <A1 sequence="1" id="001000000000000"> > <B1 sequence="3" id="001003000000000"/> > <B2 sequence="1" id="001001000000000"> > <C1 sequence="4" id="001001004000000"></C1> > <C2 sequence="11" id="001001011000000"> > <D1 sequence="01" id="001001011001000"/> > </C2> > </B2> > </A1> > > Steps to generate id value : > Note : Maximum width of id is 15. > Maximum width of sequence attribute is 3. > If the sequence is like 3, we have to replace it by > adding leading zeros > and make that sequence as 3 digit number. > 1) Get the sequence attribute value. > For example for node <A1> > Assume that id=000000000000000 > if(sequence attribute value is not null) > { > then id=sequnce value in 3 digit format+000000000000 > (eg: for A, seq value is 1. then the > result id is 001000000000000) > ) > > Here we filled the first 3 positions in the id value. > Remaining all are > zeros only. > 2) Get the sequnece attribute value of child of A1. ie..B1 node. > Because it is having the parent, id = (id value of parent) > if(sequence attribute value of current node is not null) > { > get the sequence attribute value of current node. > add this value to the computed id value of its parent. > eg: its parent id value is 001000000000000 > its sequence value is 3. > Then the new id will come like this.. > parent id : 001000000000000 > sequenc : 003 > -------------------------------------------- > Result Id : 001003000000000 > --------------------------------------------- > } > else > current id = parent id. > 3) for our xml, ids are like this > 000000000000000 > A1 001 > ----------------------------------- > 001000000000000 > B1 003 > ----------------------------------- > 001003000000000 > B2 001 > ------------------------------------------ > 001001000000000 > > For C1: 001001000000000 > 004 > -------------------------------------- > 001001004000000 > > Can any one give me the xslt code for this. > > Thanks, > Laxmi Narayana Babu.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem with generating s, David Carlisle | Thread | Re: [xsl] Problem with generating s, Mukul Gandhi |
RE: [xsl] Problem with generating s, Jarno.Elovirta | Date | Re: [xsl] Problem with generating s, Mukul Gandhi |
Month |