Hi,
Thanks for your reply, that solution worked well.
However I have encountered a problem when i tried to apply the
solution to more than one "<vendors>". The iteration becoms wrong. I
have added an XML and
an XSLT that shows the problem.
I would be very pleased if some of you could take a look at it and
propose a solution.
GeirrP
I am trying to group each vendor-company with correct company
vendor-data within each component.
So fare have I got, but it givs a wrong result:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:template match="/">
<component>
<xsl:apply-templates
select="/vendors/component/cell[(_at_)name ='Company']/value"/>
</component>
</xsl:template>
<xsl:template match="cell[(_at_)name = 'Company']/value">
<vendor>
<cell name="Company">
<xsl:copy-of select="."/>
</cell>
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates
select="/vendors/component/cell[(_at_)name ='Cage']/value1[$pos]"/>
<xsl:apply-templates
select="/vendors/component/cell[(_at_)name ='Address']/value2[$pos]"/>
</vendor>
</xsl:template>
<xsl:template match="cell[(_at_)name = 'Cage']/value1">
<cell name="Cage">
<xsl:copy-of select="."/>
</cell>
</xsl:template>
<xsl:template match="cell[(_at_)name = 'Address']/value2">
<cell name="Address">
<xsl:copy-of select="."/>
</cell>
</xsl:template>
</xsl:stylesheet>
This is the XM-file:
<?xml version="1.0" encoding="UTF-8"?>
<vendors>
<component>
<cell name="Company">
<value>AMPHENOL AEROSPACE OPERATIONS</value>
<value>ITT CANNON</value>
<value>SOURIAU CONNECTION TECHNOLOGY
(FCI)</value>
<value>DEUTSCH ECD</value>
<value>AERO ELECTRIC CONNECTOR INC</value>
<value>AMPHENOL CORPORATION</value>
<value>TEC ELECTRICAL COMPONENTS LTD</value>
</cell>
<cell name="Cage">
<value1>77820</value1>
<value1>71468</value1>
<value1>F0225</value1>
<value1>11139</value1>
<value1>59976</value1>
<value1>74868</value1>
<value1>K0690</value1>
</cell>
<cell name="Address">
<value2/>
<value2/>
<value2/>
<value2/>
<value2>TORRANCE</value2>
<value2/>
<value2/>
</cell>
</component>
<component>
<cell name="Company">
<value>AMPHENOL AEROSPACE OPERATIONS</value>
<value>ITT CANNON</value>
<value>SOURIAU CONNECTION TECHNOLOGY
(FCI)</value>
<value>DEUTSCH ECD</value>
<value>AERO ELECTRIC CONNECTOR INC</value>
<value>AMPHENOL CORPORATION</value>
<value>TEC ELECTRICAL COMPONENTS LTD</value>
</cell>
<cell name="Cage">
<value1>77820</value1>
<value1>71468</value1>
<value1>F0225</value1>
<value1>11139</value1>
<value1>59976</value1>
<value1>74868</value1>
<value1>K0690</value1>
</cell>
<cell name="Address">
<value2/>
<value2/>
<value2/>
<value2/>
<value2>TORRANCE</value2>
<value2/>
<value2/>
</cell>
</component>
</vendors>
-----Original Message-----
From: andrew welch [mailto:andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com]
Sent: 14. november 2005 11:05
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Grouping and numbering in XSLT 2.0,
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[(_at_)name =
'Company']/value"/>
</vendors>
</xsl:template>
<xsl:template match="cell[(_at_)name = 'Company']/value">
<vendor>
<cell name="Company">
<xsl:copy-of select="."/>
</cell>
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select="/vendors/cell[(_at_)name =
'Cage']/value[$pos]"/>
<xsl:apply-templates select="/vendors/cell[(_at_)name =
'Address']/value[$pos]"/>
</vendor>
</xsl:template>
<xsl:template match="cell[(_at_)name = 'Cage']/value">
<cell name="Cage">
<xsl:copy-of select="."/>
</cell>
</xsl:template>
<xsl:template match="cell[(_at_)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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--