Subject: RE: RE: RE: [xsl] merging generic elements in a parent-child From: "Matias Woloski" <woloski@xxxxxxxx> Date: Fri, 28 Jun 2002 13:41:36 -0300 |
I finally solved this... if anyone want to see the solution here it is. Thanks to all for the help! <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="TopElement" select="'Persona'"/> <xsl:output method="xml" indent="yes"/> <!-- key into the parent attributes --> <!-- where the keyed value is a combination of the parent --> <!-- key type and the value of that parent key id --> <xsl:key name="kIDs" match="root/*/@*[substring(name(),1,2) = 'id']" use="concat(substring(name(),3),'=',.)"/> <!-- key for grouping like parented and named --> <xsl:key name="kIDName" match="root/*/@*[substring(name(),1,2) = 'id']" use="concat(name(..),'|',substring(name(),3),'=',.)"/> <xsl:template match="/"> <root> <!-- select only top-level elements that have no parented element for id????? attribute --> <xsl:element name="{$TopElement}Group"> <xsl:apply-templates select="root/*[name() = $TopElement]" mode="top-levels"/> </xsl:element> </root> </xsl:template> <xsl:template match="*" mode="top-levels"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="key('kIDs',concat(name(),'=',@id))[generate-id() = generate-id(key('kIDName',concat(name(..),'|',substring(name(),3),'=',.)))]/ .." mode="group-start"> <xsl:with-param name="parent-name" select="name()"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="*" mode="group-start"> <xsl:param name="parent-name"/> <xsl:variable name="parent-id" select="@*[substring(name(),3) = $parent-name]"/> <!-- begin this child group --> <xsl:element name="{name()}Group"> <!-- show all elements parented by the same id and with the same name --> <xsl:apply-templates select="key('kIDName',concat(name(),'|',$parent-name,'=',$parent-id))/.."/> </xsl:element> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <!-- apply templates to those elements parented by this id (grouped by name) --> <xsl:apply-templates select="key('kIDs',concat(name(),'=',@id))[generate-id() = generate-id(key('kIDName',concat(name(..),'|',substring(name(),3),'=',.)))]/ .." mode="group-start"> <xsl:with-param name="parent-name" select="name()"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet> regards, Matias XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: RE: RE: [xsl] merging generic e, Dimitre Novatchev | Thread | [xsl] Selecting node contents from , Jarkko . Moilanen |
[xsl] libgd graphics in stylesheet, William S. | Date | [xsl] Processor outputs once and th, jdgarrett |
Month |