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

Re: How to access all attributes and their values ?

Subject: Re: How to access all attributes and their values ?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 01 Nov 2004 15:18:13 -0500
xslt attribute value
Thomas,

It's tempting simply to produce code that does what you want:

<xsl:template match="elem">
  <xsl:for-each select="@*">
    <xsl:text>&#xA;Attribute name=</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>Attribute value=</xsl:text>
    <xsl:value-of select="."/>
  </xsl:for-each>
</xsl:template>

But to be thorough, I also have to ask where you're looking for instruction on XSLT, since in several respects your pseudo-code is, err, "creative". You've got some things right, but other things are pretty far off.

Maybe you could use a little help from the Mulberry Quick Reference to XSLT/XPath 1.0, which is even easier, for many syntax questions, than guessing.

You'll find it at http://www.mulberrytech.com/quickref/index.html.

Cheers,
Wendell

At 02:27 PM 11/1/2004, you wrote:
For a given node I want to list all its (unknown) attribute names and (unknown) attribute values.

How do I code this within an XSLT stylesheet? It should be something similar to:

XML doc:
<elem myattr1="myval1" myattr2="myval2" myattr3="myval3">Dummy</elem>

XSLT:
...
<xsl:for-each select="\\elem[@]">
   Attribute name=<xsl:copy-of select="extractattrname(.)" />
   Attribute value=<xsl:copy-of select="extarcteattrvalue(.)" />
</xsl:for-each>

should yield:

Attribute name=myattr1 Attribute value=myval1
Attribute name=myattr2 Attribute value=myval2
Attribute name=myattr3 Attribute value=myval3

Thomas

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

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.