|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Need to output an opening or closing tag by itself
As you have discovered, your stylesheet is not a well-formed XML so it
cannot work through the XML parser.
This looks to me a positional grouping problem, which can be solved
efficiently in XSLT 1.0 with the "sibling recursion" technique.
Below is the stylesheet for the same.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/root">
<root>
<xsl:for-each select="e[@t = 'a']">
<e>
<xsl:apply-templates select="following-sibling::*[1]" />
</e>
</xsl:for-each>
</root>
</xsl:template>
<xsl:template match="*">
<xsl:if test="not(self::e[@t = 'b'])">
<xsl:copy-of select="." />
<xsl:apply-templates select="following-sibling::*[1]" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
On 6/25/08, David Frey <dpfrey@xxxxxxx> wrote:
> I have a simple XSLT problem for the gurus.
>
>
> This is my input document:
> <root>
> <e t="a"/>
> <f/>
> <f/>
> <e t="b"/>
> </root>
>
>
> This is the output document I want to produce:
> <root>
> <e>
> <f/>
> <f/>
> </e>
> </root>
--
Regards,
Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








