[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: RE: RE: merging generic elements in a parent-child
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|