[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Beginning an XPath expression with a function call

Subject: RE: Beginning an XPath expression with a function call?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 7 Mar 2003 18:04:53 -0000
xalan c xpath example
The expression substring-before(//foo/foo2, '-') is a valid XPath 1.0
expression.

In XPath 2.0 it is valid only if //foo/foo2 returns a single node. The
Saxon error message implies that it is selecting more than one node. If
you want to select only the first node, use
substring-before((//foo/foo2)[1], '-'). If you want to process all the
nodes (in XPath 2.0) use

for $x in //foo/foo2 return substring-before($x, '-')

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Monier, Yves
> Sent: 07 March 2003 16:46
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Beginning an XPath expression with a function call?
> 
> 
> Hello,
> 
> Given an XPath expression (for example //foo/foo2) that works 
> for a given xml, I would like to use the substring-before 
> function, to keep only the characters in //foo/foo2 before 
> '-'. The XPath would then become substring-before(//foo/foo2, '-')
> 
> It seems that both XPath 1.0 specs, MSXML 4, Saxon 7.4 and 
> XalanJ 2.5 refuse such construction (e.g. having a function 
> call as root of an XPath expression). Note that it works with 
> Xalan C++ 1.4. Should it, or not, regarding the specs?
> 
> Do you know if there is a simple "legal" XPath-only-based 
> solution to achieve the same result?
> 
> Many thanks,
> 
> Yves
> 
> PS:
> For MSXML 4 I use an XMLDOMDocument + the selectSingleNode function. 
> For Saxon and XalanJ I wrote programs derived from their 
> respective XPathExample and ApplyXPath samples. 
> For XalanC I wrote a program derived from its XPathWrapper sample).
> 
> Saxon error is "A sequence of more than one item is not 
> allowed here". XalanJ error is "Can not convert #STRING to a 
> NodeList!".
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.