xsl-list
[Top] [All Lists]

Problem with generating sequence ids.

2005-07-06 06:15:09

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.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--