Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Table from XML

Hi

I'm trying to create a table from an xml file using xsl. The contents of the XML file is irrelevent and unknown. I want to be able to use the xsl file on many xml files. I want to create a row for each node in the XML file. Each row being composed thus, first cell contains the node name the following cells, how ever many there may be, being an attribute name plus value pairing.

I can produce a table with the node names, no problem. But I don't know how to list/access the attributes?

The following is what I have at present and works OK. Need help on listing the attributes?

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title>Objects</title>
</head>
<body>
<table border="1">
<xsl:for-each select="//*">
<TR>
<TD>
<xsl:value-of select="name()"/>
</TD>
<!--
Here I want to do another loop and
print out all the attributes belonging to
the current node:
for each attribute
<TD>
Attribute Value
</TD>
end for each
-->
</TR>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Fanx for any assistance.
[1572 byte] By [deBooza] at [2007-11-11 8:49:28]
# 1 Re: Table from XML
Hi

I asked the same question on devshed forum. The answer, which suits my purposes exactly, follows:

<xsl:for-each select="self::node()/attribute::node()">
<td>
<xsl:value-of select="name()"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</td>
</xsl:for-each>

deBooza
deBooza at 2007-11-11 23:28:32 >