Subject: Re: [xsl] XSLT grouping(?) issue From: "Vasu Chakkera" <vasucv@xxxxxxxxx> Date: Mon, 22 Dec 2008 11:35:40 +0000 |
Different from Mukul and Mike.. <xsl:template match="Orders"> <xsl:variable name = "selected-group"> <xsl:for-each-group select="*" group-starting-with= "StartOrderGroup"> <xsl:for-each-group select="current-group()" group-ending-with= "EndOrderGroup"> <order-group> <xsl:copy-of select="current-group()"/> </order-group> </xsl:for-each-group> </xsl:for-each-group> </xsl:variable> <xsl:for-each select = "$selected-group/order-group[StartOrderGroup]"> <xsl:text>
</xsl:text> <xsl:text> Order </xsl:text> <xsl:value-of select = "StartOrderGroup/Id"/> <xsl:text>
</xsl:text> <xsl:for-each select = "*[not(self::StartOrderGroup or self::EndOrderGroup)]"> <xsl:text> 
 </xsl:text> <xsl:value-of select = "name()"/> <xsl:text> : </xsl:text> <xsl:value-of select = "Id"/> </xsl:for-each> <xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> Which ever Suits.. Vasu 2008/12/22 Mukul Gandhi <gandhi.mukul@xxxxxxxxx>: > 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>
Order
</xsl:text> > <xsl:text>-----
</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() > 1 and > position() < $indx]"> > <xsl:value-of select="local-name()" /> - <xsl:value-of > select="Id" /><xsl:text>
</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@xxxxxxxxx> 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 > > -- Vasu Chakkera Numerical Algorithms Group Ltd. Oxford www.vasucv.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT grouping(?) issue, Mukul Gandhi | Thread | Re: [xsl] XSLT grouping(?) issue, Fredde Hedberg |
Re: [xsl] XSLT grouping(?) issue, Mukul Gandhi | Date | [xsl] XPath 1 For Loop, peter verhaar |
Month |