[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: how to update a variable (grouping question)
Please try this XSL.. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/schedule"> <schedule> <xsl:apply-templates select="row" /> </schedule> </xsl:template> <xsl:template match="row"> <xsl:choose> <xsl:when test="col[2] = 'Opponent'"> <xsl:call-template name="groupSiblings"> <xsl:with-param name="month" select="col[1]" /> <xsl:with-param name="list" select="following-sibling::row" /> </xsl:call-template> </xsl:when> <xsl:otherwise /> </xsl:choose> </xsl:template> <xsl:template name="groupSiblings"> <xsl:param name="month" /> <xsl:param name="list" /> <xsl:if test="not($list[1]/col[2] = 'Opponent')"> <date><xsl:value-of select="$month" /><xsl:text> </xsl:text><xsl:value-of select="$list[1]/col[1]" /></date> <xsl:if test="count($list) >= 2"> <xsl:call-template name="groupSiblings"> <xsl:with-param name="month" select="$month" /> <xsl:with-param name="list" select="$list[position() > 1]" /> </xsl:call-template> </xsl:if> </xsl:if> </xsl:template> </xsl:stylesheet> Regards, Mukul On 8/9/05, S M <sm94066@xxxxxxxxx> wrote: > I am trying to retrieve data from a table structure (xml table) where > after every few rows a special row appears which contains a piece of > data which is relevant to rows appearing immidiatley after it (i.e. > its next few siblings). I am having hard time figuring out how to > achieve this without a dynamically assigned variable in XSL. > > Test data looks like this: > > <schedule> > <row type="header"> > <col>January</col> > <col>Opponent</col> > </row> > <row type="data"> > <col>10 at 6pm</col> > <col>Dallas</col> > </row> > <row type="data"> > <col>21 at 8pm</col> > <col>New York</col> > </row> > <row type="data"> > <col>31 at 8pm</col> > <col>Chicago</col> > </row> > <row type="header"> > <col>March</col> > <col>Opponent</col> > </row> > <row type="data"> > <col>16 at 9pm</col> > <col>Houston</col> > </row> > <row type="data"> > <col>31 at 7pm</col> > <col>Sacramento</col> > </row> > </schedule> > > and the desired output is: > <schedule> > <date>January 10 at 6pm</date> > <date>January 21 at 8pm</date> > <date>January 31 at 8pm</date> > <date>March 16 at 9pm</date> > <date>March 31 at 7pm</date> > </schedule> > > basically what I am trying to figure out is how I can save the value > of col[1] in a varaible WHEN row[@type='header'] and then append the > value of this variable to all of the following col[1] values UNTIL the > next row[@type='header] is reached ? > > Any suggestions, pointers, hints ? > > -sm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|