[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] alternative for modes
Subject: RE: [xsl] alternative for modes From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxx> Date: Fri, 13 Feb 2004 00:29:07 -0000 |
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Peter Billen > Sent: 12 February 2004 22:32 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] alternative for modes > > > Oki I think it's time for an example :) Imagine: > > <streetrace> > <car> > <owner>...</owner> > ... > </car> > <car> > <owner>...</owner> > ... > </car> > ... > </streetrace> > > Now imagine you want to print out all the cars of the > streetrace: first all in red, then in blue, sorted by the > owner of the car(in my example of course, everything is a bit > more complicated, especially the sorting code). The best I > came up with, is the following: > > <xsl:template match="streetrace> > <!-- print cars in blue !--> > <xsl:call-template name="giveCarsSorted"> > <xsl:with-param name="mode" select="'blue'"/> > </xsl:call-template> > <!-- in red !--> > <xsl:call-template name="giveCarsSorted"> > <xsl:with-param name="mode" select="'red'"/> > </xsl:call-template> > </xsl:template> > > <xsl:template name="giveCarsSorted"> > <xsl:param name="mode"/> > > <xsl:apply-templates> // this will go to each <car>-element > <xsl:sort select="car/owner"/> // sort on > <owner> in <car> > <xsl:with-param name="mode" select="$mode"/> // > propagate $mode > </xsl:apply-templates> > </xsl:template> > > <xsl:template match="car"> > <xsl:param name="mode"/> > > <xsl:if test="$mode = 'blue'"> > <font color="blue"><xsl:value-of > select="."/></font><br/> > </xsl:if> > <xsl:if test="$mode = 'red'"> > <font color="red"><xsl:value-of select="."/></font><br/> > </xsl:if> > </xsl:template> > > I hope I didn't make any big mistakes, since I haven't tested > it myself. Why are you mixing the sorting and the fact that you want blue or red ? There are many ways of solving this problem w/o modes, perhaps you could use a top level nested xsl:variable to sort the data first <xsl:variable name="data-sorted-by-owner"> <xsl:apply-templates select="//car"> <xsl:sort select="car/owner"/> </xsl:apply-templates> </xsl:variable> <xsl:variable name="data-sorted-by-car"> <xsl:apply-templates select="//car"> <xsl:sort select="car"/> </xsl:apply-templates> </xsl:variable> Then refer to $data-sorted-by-car or $data-sorted-by-owner. Use a simple match template for this and create multiple variables for whatever sorting your want...then use a named template for the color. At worst this solution may require you to use processor specific node-set function. Gl, jim fuller XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] alternative for modes, Andreas L. Delmelle | Thread | Xquery for 'hard data probs' was RE, Jim Fuller |
RE: [xsl] Grouping problem, Uslu, Cihan Y (MED) | Date | [xsl] xsl conditional: finding the , Allin Cottrell |
Month |