Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 3rd, 2008, 08:38 PM
Registered User
 
Join Date: Dec 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default [xslt 2.0] Discrepancy between Altova and Saxon-B

Hi All,

Consider the following stylesheet (in which I removes the URIs for the namespaces, because the forum engine didn't like them):

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="..." version="2.0"
    xmlns:xs="..."
    xmlns:test="test">

    <xsl:template match="/">
        <xsl:variable name="nodeWithChildren">
            <root>
                <a />
                <a />
            </root>
        </xsl:variable>
        <test-1>
            <xsl:sequence select="for $n in $nodeWithChildren/root/a return $n/position()"/>
        </test-1>
        <test-2>
            <xsl:sequence select="for $n in $nodeWithChildren/root/a return test:echo($n/position())"></xsl:sequence>
        </test-2>
    </xsl:template>

    <xsl:function name="test:echo">
        <xsl:param name="pos" as="xs:integer" />
        <xsl:sequence select="$pos"/>
    </xsl:function>

</xsl:stylesheet>
Running this with Altova XMLSpy (2008, rel 2, sp 2) returns "1 1" for both test-1 and test-2.
Running it with Saxon-B (v. 9.1.0.3) returns "1 2" for test-1 and "1 1" for test-2.

So, two questions:
* Who's right, who's wrong?
* How to tweak this code to get "1 2" in test-2?

Cordially,

Reply With Quote
  #2 (permalink)  
Old December 4th, 2008, 05:03 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Interesting question. I'm using Saxon 9.0.0.2N, and I get "1 1" for both tests.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old December 4th, 2008, 05:11 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Saxon's result is wrong for test 1. This is a known bug, see https://sourceforge.net/tracker2/?fu...72&atid=397617 and a patch is available, but not yet integrated into a maintenance release. If $n is a singleton, then $n/position() should always be 1.

To get (1,2) you need to replace the "for" with a "/" operator:

$nodeWithChildren/root/a/position()

or

$nodeWithChildren/root/test:echo(a/position())



Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old December 4th, 2008, 11:19 AM
Registered User
 
Join Date: Dec 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to both, that was fast!

The solution I did want was actually the one suggested by Michael -- I hadn't thought about it, and it really is simple. Great.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Saxon XSLT Processor booboop BOOK: Beginning XML 3rd Edition 2 April 7th, 2011 12:10 PM
XSLT not executing java function(using SAXON) dved XSLT 2 January 15th, 2008 08:46 PM
help using saxon to get some XSLT code to work hbabe42 XSLT 3 November 23rd, 2007 02:14 PM
Download code discrepancy zoltac007 ASP.NET 2.0 Basics 0 April 28th, 2006 06:34 PM
xslt-process-mode and Saxon 8 thalliley XSLT 7 October 11th, 2005 11:01 AM



All times are GMT -4. The time now is 11:37 PM.


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