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 February 23rd, 2006, 10:02 AM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default translate() problems in XSLT 2.0

The code line below works correctly using an XSLT v1.0 engine but gives the following error when using an v2.0 engine...

    "XPTY0004: A sequence of more than one item is not allowed as the first argument of translate()
Transformation failed: Run-time errors were reported"


...
<xsl:variable name="tokenmoid" select="translate(mv/moid,'=',',')"/>
...

I have had a look on the W3C website and cannot find any references to a change in the translate functionality in v2.0. Has anyone else experienced this ??

Cheers
D

 
Old February 23rd, 2006, 10:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

For any function that expects a string as an argument, if you supply a node-set containing more than one node, then:

* XSLT 1.0 will select the string-value of the first node in the node-set

* XSLT 2.0 will report an error.

If you want the 1.0 behaviour, change

translate(mv/moid,'=',',')

to

translate((mv/moid)[1],'=',',')

The reason for changing it is that this is often a latent bug - people don't realise that they are only processing the first node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 23rd, 2006, 10:40 AM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This now works although I have no idea what a "latent bug" is ? Probably the same as "user error" :)
Thanks for solving this.

 
Old February 23rd, 2006, 11:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

By latent bug I mean a bug that's been in your code for a long time but which you haven't discovered yet, typically because you haven't tested on a wide-enough range of possible input.

It's a significant problem with XSLT because people often put stylesheets into production with minimal testing.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT problems thisby XSLT 2 April 3rd, 2008 09:17 AM
XSLT - 2 problems ... prichardson XSLT 1 July 17th, 2007 12:38 PM
namespace problems in xslt stekker XSLT 2 June 16th, 2006 09:59 AM
xslt issue to translate escape sequence rk2203 XSLT 2 October 13th, 2005 07:37 AM
translate xml using xslt in a batch file? hhali XSLT 3 May 8th, 2005 12:48 PM





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