xsl-list
[Top] [All Lists]

Re: How to access all attributes and their values ?

2004-11-01 13:18:13
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[(_at_)]">
   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(_at_)mulberrytech(_dot_)com
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
======================================================================



<Prev in Thread] Current Thread [Next in Thread>