[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Grouping problem
Subject: Re: [xsl] Grouping problem From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 22 Jul 2002 21:50:13 +0100 |
Hello Mario, > Here's the more complicated version: I would like to convert the > list of <obj> elements (see INPUT below) to the hierarchical XML > (see OUTPUT below). The following works by first applying templates to only those p.array elements whose size attribute has the value 1. The template for p.array elements has a $others parameter that holds the "other" p.array elements that share the same values for their v elements. It creates an 'obj' element for the particular level of the p.array element that you're applying template to, then applies templates to the next level of p.array elements, passing in the next set of "others", those that match the next layer of v elements: <xsl:key name="arrays" match="p.array" use="v[last()]"/> <xsl:template match="r"> <xsl:copy> <xsl:apply-templates select="obj/p.array[@size = 1]" /> </xsl:copy> </xsl:template> <xsl:template match="p.array"> <xsl:param name="others" select="key('arrays', v[last()])" /> <obj name="{v[1]}"> <xsl:for-each select="$others[@size = current()/@size + 1]"> <xsl:apply-templates select="."> <xsl:with-param name="others" select="$others[v[last() - current()/@size + 1] = current()/v[1]]" /> </xsl:apply-templates> </xsl:for-each> </obj> </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping problem, Ruggier, Mario | Thread | RE: [xsl] Grouping problem, Ruggier, Mario |
[xsl] Number of nodes in a document, Satyanarayana Kakarl | Date | Re: [xsl] Number of nodes in a docu, KUMAR NINGASHETTY |
Month |
Keywords