[xsl] First positional grouping

Subject: [xsl] First positional grouping
From: "I-Lin Kuo" <ikuoikuo@xxxxxxxxxxx>
Date: Wed, 07 May 2003 17:13:19 +0000
This is my first attempt at positional grouping and I'm almost there.
I'd like to transform


<!-- source.xml --> <root> <var VGID="AA" label="Families"/> <var label="Fathers"/> <var label="Mothers"/> <var VGID="AB" label="Relatives"/> <var label="Inlaws/> </root>

into
<!-- desiredResult.xml -->
<varList VGID="AA" label="Families"/>
	<var label="Fathers"/>
	<var label="Mothers"/>
</varList>
<varList VGID="AB" label="Relatives"/>
	<var label="Inlaws/>
</varList>

by promoting all <vars> with a @VGID. I'm following the example at
http://www.dpawson.co.uk/xsl/sect2/N4486.html#d4085e229
Using the following style sheet,

<!-- myStyleSheet.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="root">
	<root>
		<xsl:for-each select="var[@VGID]">
			<varList>
				<xsl:apply-templates select="@*"/>
				<xsl:for-each select="following-sibling::var[
					  count(preceding-sibling::var[@VGID][1] | current()) = 1]">
					<xsl:copy-of select="."/>
				</xsl:for-each>
			</varList>
		</xsl:for-each>
	</root>
</xsl:template>

<xsl:template match="@*|node()" priority="-1">
	<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

</xsl:stylesheet>


I get this result: <!-- ActualResult.xml --> <root> <varList VGID="AA" label="Families"> <var label="Fathers" /> <var label="Mothers" /> <var VGID="AB" label="Relatives" /> </varList> <varList VGID="AB" label="Relatives"> <var label="Inlaws" /> </varList> </root>

which has an extra third node under the first <varList>.
Can someone help me get rid of the extra node? It should
be a matter of just amending the XPATH in the inner for-each.




I-Lin Kuo, Ann Arbor, MI Macromedia Certified ColdFusion 5.0 Advanced Developer Sun Certified Java 2 Programmer Ann Arbor Java Users Group (http://www.aajug.org)

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread