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

select elements based on another element's attributes

Subject: select elements based on another element's attributes
From: "Lars Nyman" <larsnyman@xxxxxxxxxxxxx>
Date: Wed, 24 Jul 2002 13:22:15 -0700
select element attributes
Assume a widget element with some attr elements that defines some attributes
of a widget:

   <widget widget-id="402">
      <attrs>
         <attr name="p1" public="true"/>
         <attr name="p2" public="true"/>
         <attr name="p3" public="false"/>
         <attr name="p4" public="true"/>
      </attrs>
   </widget>

A widget-ref element may refer to the above widget element.  The widget-ref
specify values for some of the attributes of the widget using attributes
named according to the attr/@name of the widget.

   <widget-ref widget-id="402" p1="v1" p2="v2" p3="v3" p5="v5"/>


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".
I intend to iterate over the attributes and emit name/value pairs.  For the
widget-ref element above I want to emit:
   p1=v1,p2=v2

Note:
   p3=v3 is not emitted because the "corresponding" attr element with
@name="p3" has @public="false"
   p5=v5 is not emitted because there is no "corresponding" attr element
with @name="p5"

So, I am looking for a select expression to use in place of either EXPR1 or
EXPR2 in the template below.

<xsl:template name="process-widget-ref">
   <xsl:param name="widget-ref"/>
   <xsl:param name="widget"/>

   <-- if iterating over widget-ref attributes -->
   <xsl:for-each select="EXPR1">
      <xsl:value-of select="name()"/>=<xsl:value-of select="."/>
      <xsl:if test="position()!=last()">,</xsl:if>
   </xsl:for-each>

   <-- if iterating over widget/attrs/attr elements -->
   <xsl:for-each select="EXPR2">
      <xsl:value-of select="@name"/>=<xsl:value-of
select="$widget-ref/@*[name()=name(current())]"/>
      <xsl:if test="position()!=last()">,</xsl:if>
   </xsl:for-each>
</xsl:template>


My initial attempt for EXPR2
   $widget/attrs/attr[@name=name($widget-ref/@*) and @public='true']
does not work since name($widget-ref/@*) returns the name of the first node
only.

Lars


 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.