Re: [xsl] Grouping and numbering in XSLT 2.0,

Subject: Re: [xsl] Grouping and numbering in XSLT 2.0,
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 14 Nov 2005 10:04:43 +0000
> The v2.0 solution to this problem, could be nice to see. So, If someone
> of you could show me, I would appreciate that.

I don't think you need any grouping or 2.0 featuers here, you just
need to apply-templates to the <value> elements of the company cell,
then to the others in the same position:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
	<vendors>
		<xsl:apply-templates select="/vendors/cell[@name = 'Company']/value"/>
	</vendors>
</xsl:template>

<xsl:template match="cell[@name = 'Company']/value">
	<vendor>
		<cell name="Company">
			<xsl:copy-of select="."/>
		</cell>
		<xsl:variable name="pos" select="position()"/>
		<xsl:apply-templates select="/vendors/cell[@name = 'Cage']/value[$pos]"/>
		<xsl:apply-templates select="/vendors/cell[@name =
'Address']/value[$pos]"/>
	</vendor>
</xsl:template>

<xsl:template match="cell[@name = 'Cage']/value">
	<cell name="Cage">
		<xsl:copy-of select="."/>
	</cell>
</xsl:template>

<xsl:template match="cell[@name = 'Address']/value">
	<cell name="Address">
		<xsl:copy-of select="."/>
	</cell>
</xsl:template>

</xsl:stylesheet>

produces:

<?xml version="1.0" encoding="utf-8"?>
<vendors>
	<vendor>
		<cell name="Company">
			<value>AMPHENOL AEROSPACE OPERATIONS</value>
		</cell>
		<cell name="Cage">
			<value>77820</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>ITT CANNON</value>
		</cell>
		<cell name="Cage">
			<value>71468</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>SOURIAU CONNECTION TECHNOLOGY (FCI)</value>
		</cell>
		<cell name="Cage">
			<value>F0225</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>DEUTSCH ECD</value>
		</cell>
		<cell name="Cage">
			<value>11139</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>AERO ELECTRIC CONNECTOR INC</value>
		</cell>
		<cell name="Cage">
			<value>59976</value>
		</cell>
		<cell name="Address">
			<value>TORRANCE</value>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>AMPHENOL CORPORATION</value>
		</cell>
		<cell name="Cage">
			<value>74868</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
	<vendor>
		<cell name="Company">
			<value>TEC ELECTRICAL COMPONENTS LTD</value>
		</cell>
		<cell name="Cage">
			<value>K0690</value>
		</cell>
		<cell name="Address">
			<value/>
		</cell>
	</vendor>
</vendors>


cheers
andrew

Current Thread