Subject: RE: [xsl] Problem with generating references. From: <Jarno.Elovirta@xxxxxxxxx> Date: Tue, 5 Jul 2005 15:52:04 +0300 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Merging descendant elemen, Matt Sims | Thread | [xsl] Problem with generating refer, Lakshmi narayana |
Re: [xsl] Problem with generating r, Joris Gillis | Date | Re: [xsl] Problem with generating r, David Carlisle |
Month |