[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: To find out immediate following tag(S)

Subject: Re: To find out immediate following tag(S)
From: "J. S. Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Tue, 07 Oct 2008 17:06:26 +0530
Re:  To find out immediate following tag(S)
Here is the complete input,xsl and required output!!!
xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="doc">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="a">
<xsl:for-each-group select="current-group() except ." group-starting-with="a1">
   <xsl:apply-templates select="." mode="group"/>
</xsl:for-each-group>
</xsl:template>

<xsl:template match="a1" mode="group">
<a1>
<xsl:apply-templates/>
</a1>
</xsl:template>

<xsl:template match="b1">
<b1>
<xsl:apply-templates/>
</b1>
</xsl:template>

</xsl:stylesheet>

input
<doc>
<a>first</a>
<a1>second</a1>
<a1>third</a1>
<a>fourth
<a1>fifth</a1>
<b1>sixth</b1>
</a>
<a1>seven</a1>
<a1>eight</a1>
<a>nine</a>
<b1>ten</b1>
<a1>ele</a1>
</doc>

Required OUTPUT
<doc>
<a>first <a1>second</a1> <a1>third</a1></a>
<a>fourth
<a1>fifth</a1>
<b1>sixth</b1>
<a1>seven</a1>
<a1>eight</a1>
</a>
<a>nine</a>
<b1>ten</b1>
<a1>ele</a1>
</doc>


At 04:58 PM 10/7/2008, Mandar Jagtap wrote:
hmm...I am not sure exactly about the issue there but one thing I
forgot to mention the mode="group". Ideally it should be like below...

<xsl:template match="a">
 <a>
 <xsl:for-each-group select="current-group() except ."
           group-starting-with="a1 | b1">
      <xsl:apply-templates mode="group"/>
</xsl:for-each-group>
</a>
</xsl:template>

<xsl:template match="a1 | b1" mode="group">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

On Tue, Oct 7, 2008 at 4:36 PM, J. S. Rawat <jrawat@xxxxxxxxxxxxxx> wrote:
> Hi Jagtap i am getting your point but it is not workable!!!
>
> At 04:25 PM 10/7/2008, Mandar Jagtap wrote:
>>
>> It was just a snippet of code not the full templates...you can try
>> something like below....you need to make changes according to the
>> actual requirement...
>>
>> <xsl:template match="a">
>> <a>
>> <xsl:for-each-group select="current-group() except ."
>>           group-starting-with="a1 | b1">
>>           <xsl:apply-templates select="." mode="group"/>
>> </xsl:for-each-group>
>> </a>
>> </xsl:template>
>>
>> <xsl:template match="a1 | b1">
>> <xsl:copy>
>> <xsl:apply-templates/>
>> </xsl:copy>
>> </xsl:template>
>>
>>
>>
>> On Tue, Oct 7, 2008 at 12:04 PM, J. S. Rawat <jrawat@xxxxxxxxxxxxxx>
>> wrote:
>> > output of this is
>> > <doc>ten</doc>
>> > only
>> >
>> > At 11:43 AM 10/7/2008, Mandar Jagtap wrote:
>> >>
>> >> Well...in that case you need to use xsl:for-each-group, I guess...for
>> >> example...
>> >>
>> >> <xsl:template match="a">
>> >> <xsl:for-each-group select="current-group() except ."
>> >>            group-starting-with="a1 | b1">
>> >>            <xsl:apply-templates select="." mode="group"/>
>> >> </xsl:for-each-group>
>> >> </xsl:template>
>> >>
>> >> Hope this helps!!
>> >>
>> >> ....Mandar Jagtap
>> >>
>> >>
>> >> On Tue, Oct 7, 2008 at 9:47 AM, J. S. Rawat <jrawat@xxxxxxxxxxxxxx>
>> >> wrote:
>> >> > Following line is copying all the following siblings. But we need
>> >> > immediate
>> >> > following siblings!!!
>> >> >
>> >> >> following-sibling::*....
>> >
>> >
>>
>>
>>
>> --
>> Thanks & Regards,
>> Mandar
>
>



--
Thanks & Regards,
Mandar

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.