ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] Retrieving unknown attribute values
by Peter Davis other posts by this author
Oct 14 2002 9:42PM messages near this date
Re: [xsl] html select with xml | RE: [xsl] Error xsl:param may not be used here
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 14 October 2002 14:28, you wrote:
>  I got fixated on attribute value templates

I guess that's a perfectly good thing to get confused about :)  Sorry for 
biting at you so hard.

I'm sure you've figured out the difference between attribute-value-templates 
and the XPath attribute:: axis (abreviated as '@') by now.

<table> 
  <tr> 
    <!-- you can output the value of an attribute when you know the name --> 
    <td> <xsl:value-of select="element/@attribute"/></td>
    
    <!-- you can output unknown attributes --> 
    <xsl:for-each select="element/@*"> 
      <td> 
        <!-- name of the current attribute --> 
        <xsl:value-of select="name()"/> 
        <xsl:text> =</xsl:text>
        <!-- value of the current attribute --> 
        <xsl:value-of select="."/> 
      </td> 
    </xsl:for-each> 
  </tr> 
</table> 

Outputting the value of an attribute is different than an attribute value 
template, which is a shortcut to using the <xsl:attribute>  tag to create an 
attribute in an element.

<foo> 
  <xsl:attribute name="bar"> 
    <xsl:value-of select="/xyz/baz"/> 
  </xsl:attribute> 
</foo> 

which is the same thing as

<foo bar="{/xyz/baz}"/> 

The point is, you only need attribute value templates and xsl:attribute if you 
want to *create* attributes on an element in the *output* document.  If you 
just want to use the value of an attribute in the *source* document, use the 
'element/@attribute' syntax.

- -- 
Peter Davis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9qzpLhDAgUT1yirARAvd0AJ0Xwev3NBDovuUXCK8q0MSJP0pBkQCgg+2T
eu0dYLJ8hv0j6/wttoNX3EM=
=yrBn
-----END PGP SIGNATURE-----


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved