Re: [xsl] Creating HTML by selecting XML attribute names

Subject: Re: [xsl] Creating HTML by selecting XML attribute names
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 15 Sep 2005 19:57:17 +0200
Hi,

Tempore 19:38:09, die 09/15/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Julian Karsten Arthur <julian.arthur@xxxxxxxxxxxxxxxxxx>:

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

It seems all necessary information is included in the XML. Just try something like:


<xsl:variable name="columns" select="/table/table-config/columns/column"/>

<xsl:template match="table">
<xsl:copy>
	<tr>
		<xsl:for-each select="$columns">
			<th><xsl:value-of select="@label"/></th>
		</xsl:for-each>	
	</tr>
    <xsl:apply-templates select="rows"/>
</xsl:copy>
</xsl:template>


<xsl:template match="field"> <xsl:variable name="field" select="."/> <tr> <xsl:for-each select="$columns"> <td> <xsl:copy-of select="@align"/> <xsl:value-of select="$field/@*[name()=current()/@field]"/> </td> </xsl:for-each> </tr> </xsl:template>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Fiat W3C in tenebris

Current Thread