xsl-list
[Top] [All Lists]

Re: [xsl] XSLT grouping(?) issue

2008-12-22 06:10:55
Here is a different algorithm, than Mike

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                       version="2.0">

  <xsl:output method="text" />

  <xsl:template match="Orders">
    <xsl:for-each-group select="*" group-starting-with="StartOrderGroup">
      <xsl:text>&#xa;Order&#xa;</xsl:text>
      <xsl:text>-----&#xa;</xsl:text>
      <xsl:variable name="curr-group" select="current-group()" />
      <xsl:variable name="indx" select="index-of(for $x in $curr-group
return $x/local-name(), 'EndOrderGroup')" />
      <xsl:for-each select="$curr-group[position() &gt; 1 and
position() &lt; $indx]">
        <xsl:value-of select="local-name()" /> - <xsl:value-of
select="Id" /><xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
    </xsl:for-each-group>
  </xsl:template>

</xsl:stylesheet>


On Mon, Dec 22, 2008 at 4:07 PM, Fredde Hedberg 
<syte_orion(_at_)yahoo(_dot_)com> 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>

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



-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
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>