Re: [xsl] start-stopping xml output

Subject: Re: [xsl] start-stopping xml output
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Fri, 23 Sep 2005 14:29:42 +0530
Please try this stylesheet(tested with Saxon 8.5.1)

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/root">
   <root>
     <xsl:apply-templates select="item" />
   </root>
</xsl:template>

<xsl:template match="item" />

<xsl:template match="item[. = 'C'][preceding-sibling::item[1] =
'B'][preceding-sibling::item[2] = 'A']">
   <xsl:call-template name="printvalues">
     <xsl:with-param name="nodeset" select="following-sibling::item" />
   </xsl:call-template>
</xsl:template>

<xsl:template name="printvalues">
   <xsl:param name="nodeset" />

   <xsl:if test="not($nodeset[1] = 'D')">
     <item><xsl:value-of select="$nodeset[1]" /></item>
     <xsl:call-template name="printvalues">
       <xsl:with-param name="nodeset" select="$nodeset[position() &gt; 1]" />
     </xsl:call-template>
   </xsl:if>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

On 9/22/05, geoff hopkins <geoffhopkins123@xxxxxxxxx> wrote:
> Thanks spot on!
>
> In addition a similar concept is that if 'A' then 'B'
> then 'C' is found in consecutive nodes then start
> reading and stop reading when 'D' is found.
>
> <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>

Current Thread