Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2008, 04:22 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

One thing that is missing from all your posts is any examples of what your input XML looks like.

If you don't have much time to get to know Saxon etc then I'd recommend Kernow. Its a simple GUI application that comes with saxon preconfigured - just point it at your XML file and XSLT file and tell it to go!

http://kernowforsaxon.sourceforge.net/

/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2008, 04:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think you are hitting a processor bug. I'm very reluctant to suggest that without evidence, which is why I have been pushing you to run it under a different processor, or at least under a different browser, which would provide that evidence. But if you're not prepared to follow the diagnostic strategy that I suggest, then I'm not sure I can help you.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 22nd, 2008, 04:29 AM
Authorized User
 
Join Date: May 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I may have an idea about what is causing the issue and I am slightly perturbed as I am not sure how to fix this.

Going back to my orginal example but with a bit more code I get a different output:

Code:
<xsl:param name="amount"/>
<xsl:param name="from"/>
<xsl:param name="to"/>

<xsl:template match="/currencies/currencyComparison">
<xsl:choose>
<xsl:when test="$from='21'"> 
<xsl:if test="$to=6">

  <xsl:variable name="Price1">
    <xsl:choose>  
      <xsl:when test="Provider='No1' and Naming='Pounds'">
        <xsl:value-of select='format-number($amount * currencyRate, "#.000")'/> 
       </xsl:when>
       <xsl:otherwise>
       </xsl:otherwise>
    </xsl:choose> 
</xsl:variable>


<xsl:variable name="Price2">
<xsl:choose>  
  <xsl:when test="Provider='B' and Naming='Pounds'">
      <xsl:value-of select='format-number($amount * currencyRate, "#.000")' /> 
  </xsl:when>
  <xsl:otherwise>
  </xsl:otherwise>
</xsl:choose> 
</xsl:variable>


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

</xsl:if>
</xsl:when> 

<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The output is:

Code:
NaNNaNNaNNaN1.895NaNNaNNaN
Is the comparision on the two variables not working because when looped through one variable maybe empty at the time? Is there a way to avoid this?

 
Old October 22nd, 2008, 04:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

As I said, it depends a lot on what your input XML looks like - without that we can't possibly say what is going on.



/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2008, 04:42 AM
Authorized User
 
Join Date: May 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[code]
Code:
<currencies>

<currency>
    <ID>21</ID>
    <BuyValue>1</BuyValue>
    <SellValue>1</SellValue>
<currency/>

<currency>
    <ID>6</ID>
    <BuyValue>2.095</BuyValue>
    <SellValue>1.937</SellValue>
<currency/>

<currencyComparison>
    <Naming>Pounds</Naming>
    <Rate>1.8834</Rate>
    <Provider>A</Provider>
</currencyComparison>

<currencyComparison>
    <Naming>Pounds</Naming>
    <Rate>1.8439</Rate>
    <Provider>B</Provider>
</currencyComparison>

</currencies>
 
Old October 22nd, 2008, 04:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well inside your template you're never going to have $Price1 and $Price2 defined at the same time, because they are in different places.

Try the following:

Code:
<xsl:template match="currencies">
  <xsl:variable name="Price1" select="currentComparision[Naming='Pounds' and Provider='A']/Rate"/>
  <xsl:variable name="Price2" select="currentComparision[Naming='Pounds' and Provider='B']/Rate"/>
  Price 1 * Price 2 = <xsl:value-of select="$Price1 * $Price2"/>
</xsl:template>

/- Sam Judson : Wrox Technical Editor -/
 
Old October 22nd, 2008, 04:53 AM
Authorized User
 
Join Date: May 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, this is it in full:

Code:
<currencies>

<currency>
<ID>21</ID>
<BuyValue>1</BuyValue>
<SellValue>1</SellValue>
</currency>

<currency>
<ID>6</ID>
<BuyValue>2.095</BuyValue>
<SellValue>1.937</SellValue>
</currency>

<currency>
<ID>10</ID>
<BuyValue>1.322</BuyValue>
<SellValue>1.222</SellValue>
</currency>

<currency>
<ID>2</ID>
<BuyValue>2.187</BuyValue>
<SellValue>1.994</SellValue>
</currency>

<currency>
<ID>5</ID>
<Country>CAN</Country>
<BuyValue>2.135</BuyValue>
<SellValue>1.947</SellValue>
</currency>

<currency>
<ID>13</ID>
<BuyValue>30.918</BuyValue>
<SellValue>27.915</SellValue>
</currency>

<currency>
<ID>14</ID>
<BuyValue>10.001</BuyValue>
<SellValue>9.117</SellValue>
</currency>

<currency>
<ID>1</ID>
<BuyValue>227.266</BuyValue>
<SellValue>206.694</SellValue>
</currency>

<currency>
<ID>15</ID>
<BuyValue>2.786</BuyValue>
<SellValue>2.54</SellValue>
</currency>

<currency>
<ID>19</ID>
<BuyValue>4.332</BuyValue>
<SellValue>3.784</SellValue>
</currency>

<currency>
<ID>16</ID>
<BuyValue>10.791</BuyValue>
<SellValue>9.837</SellValue>
</currency>

<currency>
<ID>17</ID>
<BuyValue>16.048</BuyValue>
<SellValue>14.419</SellValue>
</currency>

<currency>
<ID>18</ID>
<BuyValue>12.674</BuyValue>
<SellValue>11.554</SellValue>
</currency>

<currency>
<ID>4</ID>
<BuyValue>2.17</BuyValue>
<SellValue>1.978</SellValue>
</currency>

<currency>
<ID>20</ID>
<BuyValue>2.585</BuyValue>
<SellValue>2.296</SellValue>
</currency>

<currency>
<ID>12</ID>
<BuyValue>7.803</BuyValue>
<SellValue>7.079</SellValue>
</currency>

<currency>
<ID>11</ID>
<BuyValue>2.634</BuyValue>
<SellValue>2.301</SellValue>
</currency>

<currencyComparison>
<Naming>Pounds</Naming>
<Rate>1.8811</Rate>
<Provider>A</Provider>
</currencyComparison>

<currencyComparison>
<Naming>Pounds</Naming>
<Rate>1.895</Rate>
<Provider>B</Provider>
</currencyComparison>

<currencyComparison>
<Naming>Pounds</Naming>
<Rate>1.8834</Rate>
<Provider>C</Provider>
</currencyComparison>

<currencyComparison>
<Naming>Pounds</Naming>
<Rate>1.8439</Rate>
<Provider>D</Provider>
</currencyComparison>


</currencies>
 
Old October 22nd, 2008, 04:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, the way you are setting up the variables, if the <xsl:otherwise> branch is taken then the value of the variable will be "", which format-number() converts to NaN, which will in turn give you NaN when you do the multiplication. This isn't consistent with the information you originally gave us, that both $Price1 and $Price2 were numeric - that's why I asked for a complete sample so I could verify your statements.

It seems to me there's some flaw in your logic. You only compute a price under certain conditions, and then you compare prices even if those conditions aren't true.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 22nd, 2008, 05:09 AM
Authorized User
 
Join Date: May 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ha ha!

I am still getting my head around xslt - clearly I am finding the navigating of nodes tricky for processing in the way I would ordinarily do it in PHP for example.

Thanks Sam, you are a genius! That has been driving me mad for ages!








Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net2 xslt does not like the &lt; "<" - &gt; ">" ismailc XSLT 4 October 11th, 2008 04:40 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
Forms with XML > XSLT > XHTML kwilliams XSLT 0 October 27th, 2005 09:52 AM
"Microsoft&amp;#174;" --> "Microsoft®" rockon C# 1 October 20th, 2005 01:27 AM
XML from a DB recordset (removal of &lt;&gt;) Thodoris XML 3 July 13th, 2004 12:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.