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

Creating HTML by selecting XML attribute names

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

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
changes.

XML file >>>

<?xml version="1.0" encoding="UTF-8"?>
<table>
<table-config>
	<classes>
	<table-title-class>tituloClass</table-title-class>
	...
	</classes>
	<columns>
	<column field="name" label="Nome"/>
	<column align="right" field="age" label="Idade"/>
	</columns>
</table-config>
<rows>
	<row>
	<field age="45" name="Nome 1"/>
	</row>
	<row>
	<field age="54" name="Nome 2"/>
	</row>
	...
</rows>

XSL file excerpt >>>

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

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

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

        <!-- 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:attribute>

        </xsl:if>
        </xsl:for-each>
        <xsl:value-of select="$fieldValue"/><br/>
    </td>
    </tr>
    </xsl:template>

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,
Julian

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.