RE: [xsl] Is it possible to create xsl:sort from input parameters using XSLT 2.0 (Saxon)?

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, 2 Nov 2006 13:02:56 -0000
The value of xsl:sort select="" is an XPath expression that evaluates to the
sort key.

You are giving it an expression that evaluates to an expression that
evaluates to the sort key. 

This doesn't work. The system doesn't know that it's supposed to evaluate it
twice, how could it? If your sort keys are simple names, you can use
select="*[name()=$sortField/SortFields/SortField[1]/Sort]". If they are more
complex expressions, you need an extension like saxon:evaluate(), or you
need to generate the stylesheet dynamically from your source document.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Nick Glenister [mailto:NGlenister@xxxxxxxxxxxxxxxx] 
> Sent: 02 November 2006 12:19
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Is it possible to create xsl:sort from 
> input parameters using XSLT 2.0 (Saxon)?
> 
> Hi,
> 
> Sorry to bring this problem up again but I'm still having 
> problems with getting this sort to work.
> 
> To recap I have an XSLT that transforms XML into ASP.NET 
> which shows a list of financial products and some basic 
> details. In order to sort these products I am passing in a 
> second XML document node in the following format:
> 
> <SortFields>
> 	<SortField>
> 		<Sort>lendername</Sort>
> 		<Order>ascending</Order>
> 		<DataType>text</DataType>
> 		<CaseOrder>lower-first</CaseOrder>
> 	</SortField>
> 	<SortField>
> 		<Sort>lenderid</Sort>
> 		<Order>ascending</Order>
> 		<DataType>text</DataType>
> 		<CaseOrder>lower-first</CaseOrder>
> 	</SortField>
> 	<SortField>
> 		<Sort>productid</Sort>
> 		<Order>ascending</Order>
> 		<DataType>text</DataType>
> 		<CaseOrder>lower-first</CaseOrder>
> 	</SortField>
> </SortFields>
> 
> 
> This xml is passed into this parameter:
> 
> <xsl:param name="sortField" as="document-node()"/>
> 
> This XML document defines three levels of sorting and is 
> applied to the primary XML using the following XSLT 
> (separated over several lines for clarity in the e-mail. 
> There is one of these sort elements for each of the three sorts):
> 
> <xsl:sort select="$sortField/SortFields/SortField[1]/Sort"
> order="{$sortField/SortFields/SortField[1]/Order}" 
> data-type="{$sortField/SortFields/SortField[1]/DataType}" 
> case-order="{$sortField/SortFields/SortField[1]/CaseOrder}" />
> 
> 
> The problem is that it doesn't work. There are no errors but 
> the sorting does not occur. Doing a <xsl:value-of 
> select="$sortField/SortFields/SortField[1]/Sort"/> brings 
> through the string "lendername" I just can't see why the 
> sorting is not working. Hard coding the value "lendername" 
> sorts the output perfectly so I'm sure that XSLT is operating 
> ok in all other repects.
> 
> From what I can tell the order, data-type and case-order work 
> fine it's just the select that doesn't do anything.
> 
> I have tried creating a variable to contain the <xsl:value-of 
> select="$sortField/SortFields/SortField[1]/Sort"/> but this 
> has no effect. I have tried a function to do the same but 
> this also fails.
> 
> David Carlisle mentioned last time I asked this question the 
> following:
> 
> "Ah, but there's the rub: is $sortField a document node (/) 
> with child a SortFields element, in which case 
> $sortField/SortField[1] will select nothing, or is it a 
> SortFields element in which case $sortField/SortField[1] will 
> select something."
> 
> I don't really understand what the difference is here but 
> guess that it could be the root of my problems as $sortField 
> is a document node.
> 
> Does anyone have any ideas?
> 
> Thanks in advance
> 
> Nick
> 
> 
> 
> 
> 
> 
> 
> 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.  

Current Thread