[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can I substitute a predefined path/expression with

Subject: Re: Can I substitute a predefined path/expression within the [..] tags?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 23 Jan 2003 15:26:56 +0000
Re:  Can I substitute a predefined path/expression with
Hi Ganesh,

> I have several references in my stylesheet to a pattern that resembles:
>
> Node[@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[@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[@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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.