[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

for-each-group group-by existing and non-existing att

Subject: for-each-group group-by existing and non-existing attribute
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Mon, 28 Apr 2008 18:08:01 -0400
 for-each-group group-by existing and non-existing  att
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.