Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2007, 12:49 PM
Authorized User
 
Join Date: Oct 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 You could try using group-ending-with="close" then you will have a group of items, the last of which will always be a close element.
If I write group-ending-with="close" then this will group based on first occurence of <close>.In the given case, there can be more than one <close>....</close>. I want to end my group where a <close> is followed by <book.content> and that can happen after 2-3 occurences of <close>.

Also, is it correct that we cannot use both group-starting with and group-ending-with together, as they are mutually exclusive. Because, if there are some other elements apart from <book.content> and <close> then I don't wish to group them. Like in given example I wdon't wish to group <myname> node.

For example: In this case I want to leave <myname>Trishla</myname> as it is and would like to wrap all occurences of <book.content> and <close> in one big wrap called <book.content> with the condition that the big wrap will close wherever a <book.content> is preceded by <close> and after that a new <book.content> will start.

<books>
 <myname>trishla</myname>

 <book.content>
   <Topic>ABC</Topic>
   <author>123</author>
 </book.content>

 <book.content>
   <Topic>DEF</Topic>
   <author>456</author>
 </book.content>

  <close>
    <Index>aaa</index>
     <pages>111</pages>
      <Noname>
       <useless>one</useless>
      </Noname>
  </close>

  <close>
    <Index>bbb</index>
    <pages>222</pages>
  </close>

  <book.content>
    <Topic>GHI</Topic>
    <author>789</author>
  </book.content>
<books>

Output:
<books>
 <myname>trishla</myname>

 <book.content>
   <Topic>ABC</Topic>
   <author>123</author>
 <s></book.content></s>

 <s><book.content></s> <Topic>DEF</Topic>
   <author>456</author>
 <s></book.content></s>
  <close>
    <Index>aaa</index>
     <pages>111</pages>
      <Noname>
       <useless>one</useless>
      </Noname>
  </close>

  <close>
    <Index>bbb</index>
    <pages>222</pages>
  </close>
</book.content>

<book.content>
    <Topic>GHI</Topic>
    <author>789</author>
</book.content>
<books>

 
Old October 18th, 2007, 03:01 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

OK, I'm still not sure if you want these 'other' elements in, or out of the book.content elements, but hopefully this will give you some ideas to play around with.

Code:
<xsl:for-each-group select="book.content | close" group-ending-with="close[following-sibling::node()[1] = self::book.content]">
<book.content>
  <xsl:apply-templates select="current-group()"/>
</book.content>
</xsl:for-each-group>
/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging several tables woggysmith Access 2 December 12th, 2007 09:55 AM
merging projects Bill_Thompson Beginning VB 6 1 April 26th, 2006 04:58 PM
Merging XML Help Please sam666 XML 7 March 8th, 2006 02:50 AM
Merging two xslts into one...help!! nrane26 XSLT 1 January 7th, 2005 04:21 PM
Merging Data Mitch SQL Server 2000 0 January 2nd, 2004 05:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.