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 April 21st, 2006, 03:23 PM
Authorized User
 
Join Date: Jan 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Only Match Elements that Equal an XSL Var?

Right now I have a very small XSL file that operates on a fairly big XML doc. Using:
<xsl:template match="//page[@id=2010]">

As the root of my template results in the XSL giving me just what I want. The problem is I want 2010 in the example above to be a parameter I pass in, so more like

<xsl:template match="//page[@id=$pageId]">

Which I can't do. What's a good way to do this in XSL?

 
Old April 21st, 2006, 04:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Assuming your code is doing nothing with the other elements in the document, move the logic to the apply-templates level

<xsl:template match="/">
  <xsl:apply-templates select="//page[@id=$param]"/>
</xsl:template>

If you are processing different elements in different ways, then you will need a template rule with match="page" containing an xsl:choose, xsl:when test="@id=$param".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
giving two conditions in match in xsl:key vidhiS XSLT 2 February 29th, 2008 05:40 AM
Elements that don't match any templates clareE XSLT 3 December 21st, 2005 06:20 AM
how to match elements starting with roopa XSLT 1 October 20th, 2005 10:29 AM
xsl:template match 'overlapping' ? Kabe XSLT 1 February 25th, 2005 06:03 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.