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 February 2nd, 2007, 11:17 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default following-sibling.

Hello, I'am writing xslt transformation and want to achieve this.
I have this xml:

<Info>
 <CtrlUnit>unit1</CtrlUnit>
 <Freq>1</Freq>
 <Freq>2</Freq>
 <CtrlUnit>unit2</CtrlUnit>
 <Freq>100</Freq>
</Info>

And I want to translate it to this:

<Info>
  <CtrlUnit>unit1<x:br/>1<x:br/>2</CtrlUnit>
  <CtrlUnit>unit2<x:br/>100</CtrlUnit>
</Info>

So to select following Freqs but only to next CtrUnit.
How can I achieve this?


 
Old February 2nd, 2007, 04:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This problem is known as "positional grouping", you will find much discussion if you google for that.

In XSLT 2.0 it's easy,

<xsl:for-each-group select="*" group-starting-with="CtrlUnit">
  <CtrlUnit>
    <xsl:value-of select=".">
    <xsl:for-each select="Freq">
      <x:br/>
      <xsl:value-of select="."/>
    </
  </
</

In 1.0 it's much harder. There are basically two techniques: "sibling recursion" in which you write a recursive template that runs through the sequence of siblings one element at a time, or "Muenchian grouping", in which you reduce the problem to value-based grouping using the Muenchian method, taking generate-id(preceding-sibling::CtrlUnit[1]) as the value of the grouping key.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
checking first sibling stavinoha XSLT 2 July 4th, 2006 02:13 AM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
MDI Sibling calling Sibling... Nick.Net VB.NET 2002/2003 Basics 1 December 8th, 2003 09:23 PM
sorting and preceding-sibling iamhigh XSLT 5 August 25th, 2003 12:23 AM





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