View Single Post
 
Old March 14th, 2008, 03:12 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

So long as Item and Description always come together as a pair, you can do

<xsl:template match="FirstData">
  <xsl:copy>
    <xsl:apply-templates select="DataDesc | DataType | Item"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Item">
<Data no="{position()}">
  <xsl:copy-of select=".|following-sibling::Description[1]"/>
</Data>
</xsl:template>

If the structure is more complex, for example an Item followed by several Descriptions, then you have a positional grouping problem - easy in XSLT 2.0 with xsl:for-each-group, but quite challenging in XSLT 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference