XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - sort by variable (11)
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> ->sort by variable
-> + [XSLT Recursive Template Help]... (2)
-> + Adding values with document() ... (7)
-> + merging xml files in to single... (2)
-> + Limit description characters i... (2)
-> + problem parsing xml as text in... (2)
-> + Summarize/Distinct (5)
-> + unix epoch seconds to date str... (3)
-> + xml, xslt question (5)
-> + LGCL XSLT transformation (3)
-> + Dynamic include (3)
-> + .rdbxml as XML within Stylus ... (3)
-> + Array of Values From XSL (2)
-> + Problem Saving output (2)
-> + Base 64 encoded data embedded ... (2)
-> + XML-XML Mapping (2)
-> - Parameterized 'Document()' ...... (1)
-> + Newbie prob - Elements with sa... (3)
-> - .net 1.1 incorrectly processin... (1)
-> + xs:key and xs:keyref question (5)
-> + pass xsl-variable to javascrip... (2)
-- Previous [1321-1340] [1341-1360] [1361-1380] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 09 Oct 2006 05:27 AM
I have just this situation :


<xsl:template match="/">
<xsl:for-each select="/root" >
<xsl:for-each select="my_node" >
<xsl:for-each select="my_node_parallel" >

<!--I Create Variable and calculate value for totale_finale--> <--!I need to sort using totale_finale value -->

<xsl:value-of select="format-number($totale_finale,'#.##')" />

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>

</xsl:template>


How can I do node-set able to sorting this kind of template ?

Thanks in advance.
Regards.


Postnext
Ivan PedruzziSubject: sort by variable
Author: Ivan Pedruzzi
Date: 10 Oct 2006 10:19 AM

The snipped code doesn't give us enough information to propose a solution. Did you try using xsl:sort?

Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

Postnext
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 10 Oct 2006 11:20 AM
Originally Posted: 10 Oct 2006 11:14 AM
I cant use "sort" becouse the sort value is given by totale_finale variable.


I try to attaching my file to have some advice:



UnknownRTRIP.xml


Unknownvalute1.xml


Unknowncorpo_ritorno_3.xsl

Postnext
Ivan PedruzziSubject: sort by variable
Author: Ivan Pedruzzi
Date: 10 Oct 2006 12:13 PM

Giancarlo,

You have to implement a two pass strategy, in the first pass you build a variable with a XML fragment that contains the information you need then in the second pass to iterate on the variable sorting by totale_finale.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

Postnext
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 10 Oct 2006 04:45 PM
I supposed to do it, but I dont understand how to use the apply-template

for the creation of variable it's easy:


<xsl:variable name="base" >
<xsl:variable name="eur_currency" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. ='EUR']/following-sibling::UsdRate[1])"/>
<xsl:for-each select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/GroupList/Group" >
<xsl:variable name="pos_start" select="position()"></xsl:variable>
<xsl:variable name="supplier" select="../../Supplier"></xsl:variable>

<xsl:variable name="prezzo_gruppo" select="Price/Amount" />
<xsl:variable name="valuta_gruppo" select="Price/Currency" />
<xsl:variable name="valore_gruppo" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_gruppo]/following-sibling::UsdRate[1])"/>
<xsl:variable name="prezzo_unico" select="format-number((($prezzo_gruppo) div ($valore_gruppo)) * $eur_currency,'#.##')" />

<xsl:for-each select="OutwardList/Outward" >

<xsl:for-each select="../../ReturnList/Return" >

<xsl:variable name="posrt" select="position()" />

<xsl:variable name="valuta_ow" select="../../OutwardList/Outward[$pos]/Price/Currency" />
<xsl:variable name="valore_ow" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_ow]/following-sibling::UsdRate[1])"/>
<xsl:variable name="valuta_rt" select="../../ReturnList/Return[$posrt]/Price/Currency" />
<xsl:variable name="valore_rt" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
<xsl:variable name="valuta_un" select="../../ReturnList/Return[$posrt]/Price/Currency" />
<xsl:variable name="valore_un" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
<xsl:variable name="prezzo_ow" select="format-number(((../../OutwardList/Outward[$pos]/Price/Amount) div ($valore_ow)) * ($eur_currency),'#.##')"/>
<xsl:variable name="prezzo_rt" select="format-number(((../../ReturnList/Return[$posrt]/Price/Amount) div ($valore_rt)) * ($eur_currency),'#.##')"/>

<xsl:variable name="totale_finale" >
<xsl:choose>
<xsl:when test="Price/Amount">
<xsl:value-of select="($prezzo_ow) + ($prezzo_rt)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$prezzo_unico" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:value-of select="format-number($totale_finale,'#.##')" />

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:variable >

<!-- this is a my Idea :) -->


<xsl:variable name="basedati" select="msxsl:node-set($base)/*"/>

<xsl:template match="/">
<xsl:apply-templates select="$basedati" mode="Sorted" />
</xsl:template>


In this case it doesnt goes on error
but the page is blank :|


Postnext
Ivan PedruzziSubject: sort by variable
Author: Ivan Pedruzzi
Date: 10 Oct 2006 05:03 PM
Giancarlo,

You have to create a full XML fragment with everything you need no just

<xsl:value-of select="format-number($totale_finale,'#.##')" />

For example

<item>
<totale_finale>
<xsl:value-of select="format-number($totale_finale,'#.##')" />
</<totale_finale>
<time1> other values you may need in your table </time1>
<time2> other values you may need in your table </time2>
<time3> other values you may need in your table </time3>
</item>

then you can use a for-each to loop on you variable "base"

<xsl:for-each select="msxsl:node-set($base)/item">
<xsl:sort select="totale_finale"/>

generate HTML here

</xsl:for-each>

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 11 Oct 2006 06:38 AM
Originally Posted: 11 Oct 2006 06:37 AM
I understand the method, but i try to use it in this way ( with a simple xml fragment)


<xsl:variable name="base">
<!-- rest of the code -->

<item>
<totale_finale>
<xsl:value-of select="format-number($totale_finale,'#.##')" />
</totale_finale>
</item>

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>

</xsl:variable >



<xsl:template match="item">
<xsl:for-each select="msxsl:node-set($base)/totale_finale">
<xsl:sort select="totale_finale" order="ascending" data-type="number"/>
<b><xsl:value-of select="totale_finale"></xsl:value-of></b>
</xsl:for-each>

-------------

the result is here: http://www.lastminutesud.it/test/step3.asp?pag=0

I dont understand why are displaying all of the xml tag and not just
totale_finale

Thanks a lot.
G.

Postnext
Ivan PedruzziSubject: sort by variable
Author: Ivan Pedruzzi
Date: 11 Oct 2006 09:56 AM

Without see the entire code we can't say what is not working.

Here few comments

No need to define a template match="item", everything can be done in the main template match="/".

If you do want break down the code in different templates you have to call apply-templates and block the default template for text nodes using the following instruction

<xsl:template match="text()"/>

Ivan Pedruzzi
Stylus Studio Team

Postnext
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 11 Oct 2006 03:40 PM
Originally Posted: 11 Oct 2006 03:19 PM
Ok I understand how to build the variable

<xsl:template match="/">
<xsl:variable name="eur_currency" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. ='EUR']/following-sibling::UsdRate[1])"/>
<xsl:for-each select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/GroupList/Group" >
<xsl:variable name="pos_start" select="position()"></xsl:variable>
<xsl:variable name="supplier" select="../../Supplier"></xsl:variable>

<xsl:variable name="prezzo_gruppo" select="Price/Amount" />
<xsl:variable name="valuta_gruppo" select="Price/Currency" />
<xsl:variable name="valore_gruppo" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_gruppo]/following-sibling::UsdRate[1])"/>
<xsl:variable name="prezzo_unico" select="format-number((($prezzo_gruppo) div ($valore_gruppo)) * $eur_currency,'#.##')" />

<xsl:for-each select="OutwardList/Outward" >
<xsl:variable name="pos" select="position()" />

<xsl:for-each select="../../ReturnList/Return" >

<xsl:variable name="posrt" select="position()" />

<xsl:variable name="valuta_ow" select="../../OutwardList/Outward[$pos]/Price/Currency" />
<xsl:variable name="valore_ow" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_ow]/following-sibling::UsdRate[1])"/>
<xsl:variable name="valuta_rt" select="../../ReturnList/Return[$posrt]/Price/Currency" />
<xsl:variable name="valore_rt" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
<xsl:variable name="valuta_un" select="../../ReturnList/Return[$posrt]/Price/Currency" />
<xsl:variable name="valore_un" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
<xsl:variable name="prezzo_ow" select="format-number(((../../OutwardList/Outward[$pos]/Price/Amount) div ($valore_ow)) * ($eur_currency),'#.##')"/>
<xsl:variable name="prezzo_rt" select="format-number(((../../ReturnList/Return[$posrt]/Price/Amount) div ($valore_rt)) * ($eur_currency),'#.##')"/>

<xsl:variable name="totale_finale" >
<xsl:choose>
<xsl:when test="Price/Amount">
<xsl:value-of select="($prezzo_ow) + ($prezzo_rt)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$prezzo_unico" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="base">
<item>
<totale_finale>
<xsl:value-of select="format-number($totale_finale,'#.##')" />
</totale_finale>
</item>
</xsl:variable>

<xsl:for-each select="msxsl:node-set($base)/item" >
<xsl:sort select="totale_finale" data-type="number" order="ascending" />
<xsl:value-of select="totale_finale" /><br/>
</xsl:for-each>

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template >

I can see the totale_finale value but it is not sorted



Postnext
Ivan PedruzziSubject: sort by variable
Author: Ivan Pedruzzi
Date: 11 Oct 2006 04:58 PM


See the attached solution.



Ivan Pedruzzi
Stylus Studio Team


Unknowncorpo_ritorno_4.xsl

Posttop
giancarlo rossiSubject: sort by variable
Author: giancarlo rossi
Date: 11 Oct 2006 05:33 PM
Really thanks Ivan.

It works well.

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.