[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: Fredde Hedberg <syte_orion@xxxxxxxxx>
Date: Tue, 23 Dec 2008 13:51:20 -0800 (PST)
Re:  XSLT grouping(?) issue
Thanks Wendell! :) Merry christmas to you!


--- Den men 2008-12-22 skrev Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>:

> Fren: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
> Dmne: Re:  XSLT grouping(?) issue
> Till: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Datum: mendag 22 december 2008 18.16
> Fredde,
>
> > 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...
>
> That's irresistible.
>
> As Mike suggested, this problem is ready-made for XSLT 2.0
> group-starting-with.
>
> An XSLT 1.0 solution is not complicated, but it is subtle:
>
> <xsl:key name="item-by-group"
>  match="*[Id]"
>  use="generate-id(
>    (preceding-sibling::StartOrderGroup |
>     preceding-sibling::EndOrderGroup)[last()])"/>
>
> <xsl:template match="Orders">
>   <xsl:apply-templates
> select="StartOrderGroup"/>
> </xsl:template>
>
> <xsl:template match="StartOrderGroup">
>
> <xsl:text>&#xA;&#xA;Order&#xA;-----</xsl:text>
>   <xsl:apply-templates
> select="key('item-by-group',generate-id())"
> mode="out"/>
> </xsl:template>
>
> <xsl:template match="Car | Bus | Truck"
> mode="out">
>   <xsl:text>&#xA;</xsl:text>
>   <xsl:value-of select="local-name()"/>
>   <xsl:text> - </xsl:text>
>   <xsl:value-of select="Id"/>
> </xsl:template>
>
> <xsl:template match="StartOrderGroup |
> EndOrderGroup" mode="out"/>
>
> Notice that this ignores the Id elements on the
> StartOrderGroup (the system generated ID is more robust for
> these purposes), and ignores EndOrderGroup elements
> altogether. The trickiest thing is the way the key matches
> elements to an EndOrderGroup when they fall after a group
> ends but before the next group starts, so they can be
> skipped.
>
> Cheers,
> Wendell
>
> > Order
> > -----
> > Car - 2
> > Car - 3
> > Bus - 4
> >
> > Order
> > -----
> > Truck - 9
>
> At 05:37 AM 12/22/2008, you wrote:
> > > 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>
>
>
> ======================================================================
> Wendell Piez
> mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc.
> http://www.mulberrytech.com
> 17 West Jefferson Street                    Direct Phone:
> 301/315-9635
> Suite 207                                          Phone:
> 301/315-9631
> Rockville, MD  20850                                 Fax:
> 301/315-8285
> ----------------------------------------------------------------------
>   Mulberry Technologies: A Consultancy Specializing in SGML
> and XML
> ======================================================================


      __________________________________________________________
Ger
det lengsamt? Skaffa dig en snabbare bredbandsuppkoppling. 
Svk och jdmfvr
priser hos Kelkoo.
http://www.kelkoo.se/c-100015813-bredband.html?partnerId=96914325

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.