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

Re: select elements based on another element's attribu

Subject: Re: select elements based on another element's attributes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 24 Jul 2002 22:24:46 +0100
xsl variable based another
Hi Lars,

Before helping, I'd like to thank you for your excellently written
question. You provided a sample source, a sample output and the code
that you'd written so far, showing that you'd thought about the
problem and exactly where you were needed help. This makes it very
easy to understand what you're asking and very easy to answer. I wish
more questions were written like yours.

Anyway, to answer your question:
> During processing, I would like to select all the attr elements of
> the widget that have a "corresponding" attribute in the widget-ref
> element. Alternatively, I would like to select all the attributes of
> the widget-ref elements that have a "corresponding" attr element in
> the widget element. With "corresponding" I mean that the widget-ref
> attribute name is equal to the attr/@name, and as an additional
> constraint, the attr/@public must be "true".

Because the name() function returns the name of only the first node,
it's easiest to try to compare one name() with multiple @names than it
is to try to compare one @name with multiple name()s, so the easiest
way round is to select all the attributes of the widget-ref
elements...

  $widget-ref/@*

whose name() is equal to...

  $widget-ref/@*[name() = ...]

the @name of an attr element under the $widget...

  $widget-ref/@*[name() = $widget/attrs/attr/@name]

with the proviso that you're only interested in attr elements whose
public attribute has the value 'true'...

  $widget-ref/@*[name() = $widget/attrs/attr[@public = 'true']/@name]

To save processing, as they're the same for each $widget-ref
attribute, you should probably store the names of the relevant attr
elements in a separate variable:

  <xsl:variable name="widget-attrs"
                select="$widget/attrs/attr[@public = 'true']/@name" />
  <xsl:for-each select="$widget-ref/@*[name() = $widget-attrs]">
    ...
  </xsl:for-each>
  
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.