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

Re: attribute selection

Subject: Re: attribute selection
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 07 Apr 2005 16:22:08 -0300
xslt attribute selection
At 2005-04-07 12:10 -0700, Michael Thomas wrote:
    <property name="name1" value="value1" />
    <property name="name2" value="value2" />

...with many such property elements inside the elem1 element.

I want to print the value of the 'value' attribute for the property element that has a name of 'name1'. So far I've been doing it this way:

<xsl:for-each select="./elem1/property[./@name='name1']">
   <b><xsl:value-of select="@value"/></b>

But it seems like there should be a more concise way of doing this, especially since I know that my input document will only have one property element with a matching "@name='name1'" attribute.

Use a lookup key table:

  <xsl:key name="props" match="property" use="@name"/>
  <b><xsl:value-of select="key('props','name1')/@value"/></b>

I hope this helps.

............... Ken

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread


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.
First Name
Last Name
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.