|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Grouping within sub elements
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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








