Jeni.. that worked pretty good. For my case, the
list-variable option is probably the one I want.
Thanks a ton!!
Ganesh.
-----Original Message-----
From: Jeni Tennison [mailto:jeni(_at_)jenitennison(_dot_)com]
Sent: Thursday, January 23, 2003 9:27 AM
To: Ganesh Murthy
Cc: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Can I substitute a predefined path/expression within
the [..] tags?
Hi Ganesh,
I have several references in my stylesheet to a pattern that resembles:
Node[(_at_)name='AA' or @name='BB']
With time, I continuously need to update this pattern to include
newer attributes @name='CC', @name='DD' and so on.
Instead of repeating this addition in every match in the stylesheet,
I am wondering if there is some way to store this path/expression:
myexpression = "Node[(_at_)name='AA' or @name='BB']" or
myexpression = "@name='AA' or @name='BB' "
and use 'myexpression' in my pattern matches. That way, I will have
only one location to update. I have tried using variables without
success.
I think that the best thing is to construct a list of the names that
you're interested in and then check whether @name is in that list.
You could use a string containing the list:
<xsl:variable name="names" select="' AA BB '" />
<xsl:apply-templates
select="Node[contains($names, concat(' ', @name, ' '))]" />
Or you could construct a node set containing the names as a list of
elements. For example, you could have a separate document, names.xml,
that looked like:
<names>
<name>AA</name>
<name>BB</name>
</names>
and then do:
<xsl:variable name="names"
select="document('names.xml')/names/name" />
<xsl:apply-templates select="Node[(_at_)name = $names]" />
You could use the latter method with a result tree fragment that you
convert to a node set using an extension node-set() function if you
didn't want to create a separate document.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list