Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 May 6th, 2008, 11:15 AM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Param in template match=" "

I have a XSLT where I’m getting a variety of Parameters from a variety of sources. All of these Parameters are supplied as plain strings.

For example <xsl:param name="ElementName" select="/.." /> might be fed the plain value of 'Apple'.

Others look like <xsl:param name="Pathstring" select="/.." /> and contain '//Parent/Apple|//Parent/Oranges'.

In the case of the param $Pathstring, I make use of saxon:evaluate() to parse the string into a valid xpath expression. I understand this portion of it.

But I need to create a template match by using the string supplied in a param as PART of an expression. I'm having some troubles doing this.

I know this isn't correct, but it shows what I'm logically trying to do. I would like a template that matches like this.
Code:
<xsl:template match="Parent/$ElementName">
    DO SOMETHING
</xsl:template>
In other words I want the match="Parent/$ElementName" to evaluate as a valid xpath expression match="Parent/Apples" Taking the string from the parameter and using as part of xpath expression. I've tried making use of the saxon:evaluate and expression functions in combination to get it to match correctly. I'm still new to XSLT and staring at this any longer is just confusing me :)

Thanks, this community has been really helpful.







 
Old May 7th, 2008, 04:57 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

Although saxon:evaluate allows you to construct XPath expressions dynamically, there is no equivalent allowing you to construct match patterns dynamically.

But your example of Parent/$ElementName can be achieved using

Parent/*[name()=$ElementName]

or perhaps

Parent/*[saxon-evaluate($path)]

However, performance is likely to be awful. You may be better off generating an XSLT stylesheet dynamically and then executing it - I've done that successfully for applications like this.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 7th, 2008, 07:37 AM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Yep,

I figured it out last evening and didn't have a chance to come in and remove this post. Thank you as always.

(Luckily performance isn't an issue for this application)

Ryan





Similar Threads
Thread Thread Starter Forum Replies Last Post
value-of inside template match RoeZ XSLT 5 April 17th, 2008 12:09 PM
Is this possible <call-template name="$param"/>? rushman XSLT 2 April 12th, 2007 01:04 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
template m,atch doesnt match Tomi XSLT 1 March 9th, 2007 07:56 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM





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