Subject: Re: [xsl] Recursive grouping won't recurse... From: "Robert S. Koberg" <rob@xxxxxxxxxx> Date: Thu, 04 Jul 2002 10:33:46 -0700 |
I'm still shaky on grouping with keys so I've probably missed something obvious, but I can't get a grouping to work when it has to group on a recursive structure. The input looks essentially like the following:
<list> <a type="1" flag="false"/> <b type="2" flag="false"/> <c type="3" flag="false"> <d type="4" flag="true"/> <e type="4" flag="true"/> <f type="5" flag="true"/> <g type="5" flag="true"/> </c> </list> <list> <a type="1" flag="false"/> <b type="2" flag="false"/> <c type="3" flag="false"> <d type="7" flag="false"> <e type="4" flag="true"/> <e type="4" flag="true"/> </d> </c> </list>
Where, if there are adjacent nodes with the same type than the flag will be true, otherwise the flag will always be false. It could be possible for adjacent nodes to have the same type with the flag set to false. The same structure could go many more levels deep than shown here. The desired output is
<xsl:template match="list"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="a | b | c | d | e | f"> <xsl:element name="name()"> <xsl:attribute name="type"> <xsl:value-of select="@type"/> </xsl:attribute> <xsl:attribute name="flag"> <xsl:value-of select="@flag"/> </xsl:attribute> <xsl:if test="boolean(./*)"> <group> <xsl:apply-templates/> </group> </xsl:if> </xsl:element> </xsl:template>
best, -Rob
<list> <a type="1" flag="false"/> <b type="2" flag="false"/> <c type="3" flag="false"> <group> <d type="4" flag="true"/> <e type="4" flag="true"/> </group> <group> <f type="5" flag="true"/> <g type="5" flag="true"/> </group> </c> </list> <list> <a type="1" flag="false"/> <b type="2" flag="false"/> <c type="3" flag="false"> <d type="7" flag="false"> <group> <e type="4" flag="true"/> <e type="4" flag="true"/> </group> </d> </c> </list>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Recursive grouping won't recu, Hunsberger, Peter | Thread | Re: [xsl] Recursive grouping won't , Robert S. Koberg |
[xsl] Recursive grouping won't recu, Hunsberger, Peter | Date | Re: [xsl] Recursive grouping won't , Robert S. Koberg |
Month |