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

Re: Grouping within sub elements

Subject: Re: Grouping within sub elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 29 Jan 2005 08:38:33 -0500
xsl sub
At 2005-01-29 07:45 +0000, Steve W wrote:
I have been trying to use the Muenchian method to group sub-elements within
a particular element.
...
Can I apply the same sort of logic within an item group,  to get some output
something like :
...
I can't help thinking I'm missing something obvious but can't see it !

One isn't obliged to use the Muenchian group for sub-document-scope grouping, which is the case also when doing multiple-level grouping. I sometimes find variable-based grouping to be more understandable because then I'm dealing with all those constructs that need to be grouped in a single variable, rather than having to deal with document-wide scope. The Muenchian method always has document-wide scope, but you can assign any subset of a document to a variable.


This variable-based method is also very useful grouping across multiple documents, whereas the Muenchian Method's document-wide scope is not viable because you are only ever dealing with a single document.

The idea is to walk through a variable of constructs (however you've decided to create the variable) finding the first of a set, much like the Muenchian Method.

I hope this helps.

............................ Ken

T:\ftemp>type steve.xml
<BODY>
    <ITEM>
        <ID>AA</ID>
        <SUBITEM>1</SUBITEM>
        <SUBITEM>2</SUBITEM>
        <SUBITEM>1</SUBITEM>
        <SUBITEM>3</SUBITEM>
        <SUBITEM>2</SUBITEM>
    </ITEM>
    <ITEM>
        <ID>BB</ID>
        <SUBITEM>1</SUBITEM>
        <SUBITEM>4</SUBITEM>
        <SUBITEM>1</SUBITEM>
        <SUBITEM>4</SUBITEM>
        <SUBITEM>4</SUBITEM>
    </ITEM>
    <ITEM>
        <ID>CC</ID>
        <SUBITEM>2</SUBITEM>
        <SUBITEM>2</SUBITEM>
        <SUBITEM>3</SUBITEM>
        <SUBITEM>3</SUBITEM>
        <SUBITEM>2</SUBITEM>
    </ITEM>
</BODY>

T:\ftemp>saxon steve.xml steve.xsl

Item AA
Subitems 1, 2, 3
Item BB
Subitems 1, 4
Item CC
Subitems 2, 3
T:\ftemp>type steve.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each select="/BODY/ITEM">
Item <xsl:value-of select="ID"/><xsl:text>
Subitems </xsl:text>
    <xsl:variable name="subs" select="SUBITEM"/>
    <xsl:for-each select="$subs">
      <xsl:if test="generate-id(.)=
                    generate-id($subs[.=current()])">
        <xsl:if test="position()>1">, </xsl:if>
        <xsl:value-of select="."/>
      </xsl:if>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>


-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.