xsl-list
[Top] [All Lists]

RE: [xsl] XSLT grouping(?) issue

2008-12-22 05:53:19
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(_at_)yahoo(_dot_)com] 
Sent: 22 December 2008 10:38
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] 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


      ___________________________________________________
Sök efter kärleken!
Hitta din tvillingsjäl på Yahoo! Dejting: 
http://ad.doubleclick.net/clk;185753627;24584539;x?http://se.m
eetic.yahoo.net/index.php?mtcmk=148783

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>