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

RE: XSLT grouping(?) issue

Subject: RE: XSLT grouping(?) issue
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 22 Dec 2008 10:52:53 -0000
RE:  XSLT grouping(?) issue
In XSLT 2.0, use

<xsl:for-each-group group-starting-with="StartOrderGroup">
  <xsl:variable name="start"
select="current-group()[self::StartOrderGroup]"/>
  <xsl:variable name="end" select="current-group()[self::EndOrderGroup]"/>
  <xsl:variable name="group" select="current-group()[. >> $start and . <<
$end]
  <order>
    <xsl:for-each-select="$group">
      <xsl:value-of select="name()"/> - <xsl:value-of select="Id"/>
    </xsl:for-each>
  </order>
</xsl:for-each-group>

plus some formatting as required.

For a 1.0 solution, use sibling recursion, which is a but more difficult.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Fredde Hedberg [mailto:syte_orion@xxxxxxxxx]
> Sent: 22 December 2008 10:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  XSLT grouping(?) issue
>
> > The problem is solvable with XSLT, provided your input XML is well
> > formed. But your input is not a valid XML document.
> >
> > for e.g., <Id=1/> is not a valid XML fragment, and XML parser
> > complains about it.
>
> My mistake, I apologize. When I simplified my XML I made it
> more bad formed than it really is...
>
> <Orders>
>   <StartOrderGroup>
>     <Id>1</Id>
>   </StartOrderGroup>
>   <Car>
>     <Id>2</Id>
>   </Car>
>   <Car>
>     <Id>3</Id>
>   </Car>
>   <Bus>
>     <Id>4</Id>
>   </Bus>
>   <EndOrderGroup>
>     <Id>5</Id>
>   </EndOrderGroup>
>   <Car>
>     <Id>6</Id>
>   </Car>
>   <Truck>
>     <Id>7</Id>
>   </Truck>
>   <StartOrderGroup>
>     <Id>8</Id>
>   </StartOrderGroup>
>   <Truck>
>     <Id>9</Id>
>   </Truck>
>   <EndOrderGroup>
>     <Id>10</Id>
>   </EndOrderGroup>
> </Orders>
>
> That's at least valid XML :)
> You've given me hope by saying it is solvable. Will this new
> XML-fragment allow you to show me how? That would basically
> save christmas for me...
>
> Regards
>
> Fredde
>
>
>       ___________________________________________________
> Svk efter kdrleken!
> Hitta din tvillingsjdl pe Yahoo! Dejting:
> http://ad.doubleclick.net/clk;185753627;24584539;x?http://se.m
> eetic.yahoo.net/index.php?mtcmk=148783

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.