xsl-list
[Top] [All Lists]

RE: Problem with generating references.

2005-07-05 05:52:04
Hi,

I want to write an XSL file which results in XML file. The 
transformation
should be like this..
Note : For the nodes in the above xml file, no attribute is there to
identify uniquely (No ids are there. But in the result tree, 
I want unique
id for each element so that I can identify each element uniquely).

Use generate-id(), unless you want the ID to mean something and not just be 
unique within that single transformation process.
 
1. Divide the elements into groups.
2. While dividing, create the references to the elements in 
the current
group which are going to be placed in another group.

I want the output XML like this...
<A-Group>
         <A1>
                  <reference id="(id of B1)" />

Say the id of B1 is X

                  <reference id="(id of B2)" />
         </A1>
</A-Group>
<B-Group>
         <B1/>

How do you know this is X without marking it up? 

        <xsl:key name="group" match="*" use="substring(name(), 1, 1)"/>
        
        <xsl:template match="/">
                <xsl:for-each select="descendant::*[generate-id() = 
generate-id(key('group', substring(name(), 1, 1)))]">
                        <xsl:variable name="group" select="substring(name(), 1, 
1)"/>
                        <xsl:element name="{$group}-Group">
                                <xsl:for-each select="key('group', $group)">
                                        <xsl:copy>
                                                <xsl:attribute name="id">
                                                        <xsl:value-of 
select="generate-id()"/>
                                                </xsl:attribute>
                                                <xsl:for-each select="*">
                                                        <reference 
id="{generate-id()}"/>
                                                </xsl:for-each>
                                        </xsl:copy>
                                </xsl:for-each>
                        </xsl:element>
                </xsl:for-each>
        </xsl:template>

Cheers,

Jarno

--
In Strict Confidence: Eye Of Heaven

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>