[xsl] Creating HTML by selecting XML attribute names

Subject: [xsl] Creating HTML by selecting XML attribute names
From: "Julian Karsten Arthur" <julian.arthur@xxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Sep 2005 14:38:09 -0300

I am trying to convert some XML to HTML using the latest version of Xalan.
However, I am having difficulty in selecting the correct elements from my XML
source file. What I am trying to do is select the data from the
rows/row/fields in the order it appears in the columns/column, and output it
to a HTML table. The XML itself is generated so the attributes of the columns
could change each time. I.e. in this example we have the attributes 'name' and
'age', but next time round they could be 'title', 'name', 'address'.

How can I select each of the attributes of the column, and then query the
fields in the order specified in the source file?

I have something that works for the XML in this example, but not if the XML

XML file >>>

<?xml version="1.0" encoding="UTF-8"?>
	<column field="name" label="Nome"/>
	<column align="right" field="age" label="Idade"/>
	<field age="45" name="Nome 1"/>
	<field age="54" name="Nome 2"/>

XSL file excerpt >>>

<xsl:template match="rows">
    <xsl:apply-templates select="row/field"/>

    <xsl:template match="row/field">
    I have this: <field age="45" name="Nome 1"/>. But the attributes may
    I need to get a handle on the attributes.

    <xsl:variable name="fieldName" select="@name"/>
    <xsl:variable name="fieldValue" select="@age"/>
        <xsl:value-of select="$fieldName"/><br/>

        <!-- This successfully loops through the columns -->
        <xsl:for-each select="/table/table-config/columns/column">

        <xsl:if test="@field = 'age'">
        <xsl:attribute name="align">
            <xsl:value-of select="@align"/>

        <xsl:value-of select="$fieldValue"/><br/>

The output I want is:
Name		Age
Nome 1		45
Nome 2             54

...but it needs to change if the input XML provides additional columns. Is
this possible using XSLT?

Thoughts appreciated. With Regards,

Current Thread