Re: [xsl] start-stopping xml output

Subject: Re: [xsl] start-stopping xml output
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 22 Sep 2005 11:57:31 +0200
Hi,
Tempore 11:41:35, die 09/22/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit geoff hopkins <geoffhopkins123@xxxxxxxxx>:

<root>
	<item>Z</item>
	<item>A</item>
	<item>B</item>
	<item>C</item>
	<item>BOB1</item>
	<item>BOB2</item>
	<item>BOB3</item>
	<item>BOB4</item>
	<item>D</item>
	<item>BOB5</item>
	<item>BOB6</item>
	<item>A</item>
	<item>BOB7</item>
	<item>B</item>
	<item>BOB8</item>
	<item>C</item>
	<item>BOB9</item>
	<item>B</item>
	<item>BOB10</item>
</root>

output would look something like this

<root>
	<item>BOB1</item>
	<item>BOB2</item>
	<item>BOB3</item>
	<item>BOB4</item>	
</root>


I think this would work:


<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes"/>
	
<xsl:template match="root">
<xsl:copy>
	<xsl:apply-templates select="item[1]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="item[.='A']">
<xsl:apply-templates select="(following-sibling::item[1][.='B']|
	following-sibling::item[.='A'][1])[1]"/>
</xsl:template>

<xsl:template match="item[.='B']">
<xsl:apply-templates select="(following-sibling::item[1][.='C']|
	following-sibling::item[.='A'][1])[1]"/>
</xsl:template>

<xsl:template match="item">
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::item[1]"/>
</xsl:template>

<xsl:template match="item[.='Z' or .='C']">
<xsl:apply-templates select="following-sibling::item[1]"/>
</xsl:template>

<xsl:template match="item[.='D']">
<xsl:apply-templates select="following-sibling::item[.='A'][1]"/>
</xsl:template>

</xsl:stylesheet>

Most likely, it is possible to create a more generic solution, but I don't know to what extent your real XML differs from your examples.

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+Error, keyboard not foundb press F1 to continueB; , BIOS

Current Thread