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 September 5th, 2006, 09:22 AM
Vx Vx is offline
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default String xsl:param as XPath expression

I have global parameter containing string of XPath expression
<xsl:param name="ItemQuery" select="'//Item'" />
I need to use this parameter later as a value for select attribute:
Code:
<xsl:for-each select="$ItemQuery" >            
  <xsl:call-template name="item" />
</xsl:for-each>
But having used syntax above I got an error 'ItemQuery' must evaluate to a node list.
What should I do to use string literal '//Item' as XPath expression for select attribute?
Thanks

 
Old September 5th, 2006, 09:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Using standard XSLT you can't. There are three options
  • Use an extension function, Saxon provides one; I think it's called saxon:parse but you'll have to check.
  • If the XPath is simple you can often rewrite to something like //*[name() = $ItemQuery]; this is okay if you're just passing an element name.
  • Pass a node-set instead of a string as the parameter; how you do this depends on the processor.

--

Joe (Microsoft MVP - XML)
 
Old September 5th, 2006, 09:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Standard XSLT doesn't allow you to construct an XPath expression as a string at run-time. But some products have extension functions (usually called xx:eval() or xx:evaluate()) that meet this requirement.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 5th, 2006, 09:57 AM
Vx Vx is offline
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe and Michael,
Thank you, I got the point.

 
Old September 5th, 2006, 10:18 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by mhkay
 Standard XSLT doesn't allow you to construct an XPath expression as a string at run-time. But some products have extension functions (usually called xx:eval() or xx:evaluate()) that meet this requirement.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Then it'll be saxon:evaluate then :)

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
XSL Param with XPath expressions V4mp1r3 XSLT 7 June 1st, 2007 11:47 AM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM
Explanation asked about XSL/XPath expression PeterMeeuwsen XSLT 2 December 15th, 2003 06:29 PM





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