[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] for-each-group group-by existing and non-existing attribute
Subject: [xsl] for-each-group group-by existing and non-existing attribute From: Robert Koberg <rob@xxxxxxxxxx> Date: Mon, 28 Apr 2008 18:08:01 -0400 |
Hi, (o;?o;?XSL, expected output and XML source below) o;?I want to group children of the root element by two attributes (idref and value). The the value attribute will default to true (by the XSL, not schema defined) if not included. So, I want the element in the group regardless of whether the validation element has a value attribute. But, I only want the child included if it has an idref attribute. Is this possible? The XSL is my attempt but I understand why it does not work. Just don't understand how to make it work, if it is possible. o;? XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="/container"> <test> <xsl:for-each-group select="*[.//validation[@idref]]" group-by=".//validation[@idref and @value]"> <xsl:variable name="validation-node" select=".//validation[1]"/> <xsl:variable name="value" select="if ($validation-node[1]/@value) then $validation-node/@value else true"/> <group condition="{@idref} == {$value}"> <xsl:for-each select="current-group()"> <xsl:copy-of select="."/> </xsl:for-each> </group> </xsl:for-each-group> </test> </xsl:template> </xsl:stylesheet> --------------------------------------------------- Expected output: <test> <group condition="isFoo == true"> <property name="foo"> <validation idref="isFoo"/> </property> <sub> <property name="baz"> <validation idref="isFoo"/> </property> </sub> </group> <groupo;? condition="isFoo == false <property name="bar"> <validation idref="isFoo" value="false"/> </property> <property name="bat"> <sub> <validation idref="isFoo" value="false"/> </sub> </property> </group> <groupo;? condition="isBar == true"> <property name="foh"> <validation idref="isBar"/> </property> </group> </test> ----------------------------------------- XML: <?xml version="1.0" encoding="UTF-8"?> <container> <property name="foo"> <validation idref="isFoo"/> </property> <property name="fof"> <validation/> </property> <property name="foh"> <validation idref="isBar"/> </property> <property name="bar"> <validation idref="isFoo" value="false"/> </property> <sub> <property name="baz"> <validation idref="isFoo"/> </property> </sub> <property name="bat"> <sub> <validation idref="isFoo" value="false"/> </sub> </property> </container>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem with iterating th, Colin Adams | Thread | Re: [xsl] for-each-group group-by e, David Carlisle |
Re: [xsl] Problem with iterating th, Dimitre Novatchev | Date | Re: [xsl] for-each-group group-by e, David Carlisle |
Month |