[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

Subject: Re: Need to output an opening or closing tag by itself
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 25 Jun 2008 12:58:48 +0530
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.