p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Param in template match=" " (http://p2p.wrox.com/showthread.php?t=67938)

iceandrews May 6th, 2008 11:15 AM

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.

<xsl:template match="Parent/$ElementName">

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.

mhkay May 7th, 2008 04:57 AM

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


or perhaps


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
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

iceandrews May 7th, 2008 07:37 AM


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)


All times are GMT -4. The time now is 09:07 AM.

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