Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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 Display Modes
  #1 (permalink)  
Old September 5th, 2006, 09:22 AM
Vx Vx is offline
Registered User
 
Join Date: Mar 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old September 5th, 2006, 09:35 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 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)
Reply With Quote
  #3 (permalink)  
Old September 5th, 2006, 09:48 AM
mhkay's Avatar
Wrox Author
Points: 17,731, Level: 57
Points: 17,731, Level: 57 Points: 17,731, Level: 57 Points: 17,731, Level: 57
Activity: 70%
Activity: 70% Activity: 70% Activity: 70%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,833
Thanks: 0
Thanked 266 Times in 261 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
Reply With Quote
  #4 (permalink)  
Old September 5th, 2006, 09:57 AM
Vx Vx is offline
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #5 (permalink)  
Old September 5th, 2006, 10:18 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 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)
Reply With Quote
Reply


Thread Tools
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
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 06: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 05:29 PM



All times are GMT -4. The time now is 04:21 PM.


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