Homer wrote:
Hi All,
I have following XML File:
<Header></Header>
<Category></Category>
<Item1></Item1>
<Item2></Item2>
<Category></Category>
<Item3></Item3>
I hope you don't mean that. I hope you mean
<doc>
<Header></Header>
<Category></Category>
<Item></Item>
<Item></Item>
<Category></Category>
<Item></Item>
</doc>
(in other words, three occurrences of the Item element type, not one
each of three separately-named element types Item1, Item2, and Item3).
Could someone please send me an example what is the XSLT text to
convert it to:
<Header>
<Category>
<Item1></Item1>
<Item2></Item2>
</Category>
<Category>
<Item3></Item3>
</Category>
</Header>
<?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="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Category">
<Category>
<xsl:apply-templates
select="following-sibling::Item
[generate-id(preceding-sibling::Category[1]) =
generate-id(current())]" mode="included"/>
</Category>
</xsl:template>
<xsl:template match="Item"/>
<xsl:template match="Item" mode="included">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
///Peter
--
XML FAQ:
http://xml.silmaril.ie/