Subject: RE: [xsl] Is it possible to create xsl:sort from input parameters using XSLT 2.0 (Saxon)? From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 27 Jul 2006 15:52:22 +0100 |
The select attribute expects an XPath expression, so that's fine. The order, data-type, and case-order attributes are AVTs, so the expression must go within curly braces. An alternative approach to this kind of problem is to generate the "source" stylesheet programmatically. You can't do this "inline" as you attempted (a stylesheet can't modify itself), but you can write one stylesheet that writes another as its output. If you do need to handle a variable number of sort keys, it can in theory be done by repeated sorting on one sort key at a time, starting with the last one. (I remember watching people doing that with punched cards....). But this may be inefficient. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Nick Glenister [mailto:NGlenister@xxxxxxxxxxxxxxxx] > Sent: 27 July 2006 14:33 > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' > Subject: RE: [xsl] Is it possible to create xsl:sort from > input parameters using XSLT 2.0 (Saxon)? > > Hi, > > Thanks for the reply, it make perfect sense. I will try the > following instead which will limit me to a maximum of three > sorts but is probably more than enough in practice. > > <xsl:for-each select="$tempRoot/product"> > <xsl:choose> > <xsl:when test="boolean($sortField)=true"> > > <xsl:sort select="$sortField/SortField[1]" > order="$sortField/SortField[1]/@Order" > data-type="$sortField/SortField[1]/@DataType" > case-order="$sortField/SortField[1]/@CaseOrder" /> > > <xsl:sort select="$sortField/SortField[2]" > order="$sortField/SortField[2]/@Order" > data-type="$sortField/SortField[2]/@DataType" > case-order="$sortField/SortField[2]/@CaseOrder" /> > > <xsl:sort select="$sortField/SortField[3]" > order="$sortField/SortField[3]/@Order" > data-type="$sortField/SortField[3]/@DataType" > case-order="$sortField/SortField[3]/@CaseOrder" /> > > </xsl:when> > </xsl:choose> > </xsl:for-each> > > > Cheers > > Nick > > -----Original Message----- > From: Huditsch, Roman (LNG-VIE) [mailto:Roman.Huditsch@xxxxxxxxxxxxx] > Sent: 27 July 2006 13:55 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] Is it possible to create xsl:sort from > input parameters using XSLT 2.0 (Saxon)? > > > Hi Nick, > > As far as I can tell, it is not possible to generate > <xsl:sort> instructions that way, since the <xsl:sort>s in > your example would only apply to your inner for-each loop. > Is a two-pass solution also suitable for you? > > best regards, > Roman > > > -----Original Message----- > > From: Nick Glenister [mailto:NGlenister@xxxxxxxxxxxxxxxx] > > Sent: Thursday, July 27, 2006 1:01 PM > > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' > > Subject: [xsl] Is it possible to create xsl:sort from input > parameters > > using XSLT 2.0 (Saxon)? > > > > Hi, > > > > I am trying to create dynamic sorts in my XSLT file so the end user > > can select different fields to sort the data on then rerun the XSLT. > > > > The XSLT is called from a vb.net app where the chosen sort > fields are > > passed as XML into a param called sortField: > > > > <SortFields> > > <SortField DataType="number" CaseOrder="lowercasefirst" > > Order="ascending">lenderid</SortField> > > <SortField DataType="number" CaseOrder="lowercasefirst" > > Order="ascending">generalproductid</SortField> > > </SortFields> > > > > Using the following XSL: > > > > <xsl:for-each select="$tempRoot/product"> > > <xsl:choose> > > <xsl:when test="boolean($sortField)=true"> > > <xsl:for-each > > select="$sortField/SortFields/SortField"> > > <xsl:sort select="." > > order="@Order" > > data-type="@DataType" case-order="@CaseOrder" /> > > </xsl:for-each> > > > > </xsl:when> > > </xsl:choose> > > </xsl:for-each> > > > > > > which (in my head at least) would result in something akin too: > > > > <xsl:for-each select="$tempRoot/product"> > > <xsl:sort select="lenderid" order="ascending" > > data-type="number" case-order="lowercasefirst"/> > > <xsl:sort select="generalproductid" order="ascending" > > data-type="number" case-order="lowercasefirst"/> > > </xsl:for-each> > > > > > > The main input XML document which is being transformed looks like > > this: > > > > <root> > > <product> > > <lenderid>1234</lenderid> > > <generalproductid>12344321</genrealproductid> > > <lendername>fred</lendername> > > ... > > </product> > > <product> > > ... > > </product> > > </root> > > > > > > Having tried doing it I'm now pretty sure that this isn't > possible as > > I get a compile error on the xsl:sort order as it is expecting > > ascending or descending. > > > > Is there any other way of achieving this? > > > > > > Cheers > > > > Nick > > > > > > > > > > The Investment, Life & Pensions Annual Awards Lunch 2006 will take > > place on Wednesday 20th September at The Brewery, Chiswell Street, > > London. To book your table or for more information, contact Miranda > > Siliprandi on 0870 2250 491 or email msiliprandi@xxxxxxxxxxxxxxxx > > > > The Moneyfacts 11th Annual Conference takes place on Tuesday 7th > > November 2006 at the Shaw Centre, Novotel Euston London in > association > > with our Platinum Sponsors, CACI. For sponsorship and > general enquires > > please email Anne Joyce at ajoyce@xxxxxxxxxxxxxxxx or to > reserve your > > place, call our ticket hotline on 0870 2250 100. > > > > E-mail Disclaimer: This e-mail message contains confidential > > information and is intended only for the individual entity or > > organisation named. If you are not the named addressee you > should not > > disseminate, distribute, print or copy this e-mail and/or > attachments > > (either whole or partial). To do so may constitute a breach of > > confidence and/or privilege. Please notify the sender > immediately by > > e-mail if you have received this e-mail by mistake and delete this > > e-mail permanently from your system. E-mail transmissions cannot be > > guaranteed to be secure or error-free as information could be > > intercepted, corrupted, lost, destroyed, maliciously > altered, arrive > > late or incomplete, or contain viruses. The sender > therefore does not > > accept liability for any errors or omissions in the > contents of this > > message, which arise as a result of e-mail transmission. If > > verification is required please request a hard-copy version. Please > > note that any views or opinions presented in this e-mail are ! > > those of the author and do not necessarily represent those of > > Moneyfacts Group plc or their affiliates. Whilst every step > is taken > > to ensure e-mails are virus free when they leave Moneyfacts Group > > systems, we accept no liability for > > any damage caused by any virus received. This outbound > > message has been scanned for viruses by MailControl for Moneyfacts > > Group plc. > > > > This inbound message has been scanned for viruses by > MailControl for Moneyfacts Group plc.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Is it possible to create , Nick Glenister | Thread | RE: [xsl] Is it possible to create , Nick Glenister |
[xsl] Attempt to access a lazily-ev, cknell | Date | RE: [xsl] Attempt to access a lazil, Michael Kay |
Month |