Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] How to access all attributes and their values ?

From: Wendell Piez <wapiez@---------------->
To:
Date: 11/1/2004 9:00:00 PM
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
======================================================================


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent