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
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext 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.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
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.