|
next
|
Subject: HTML Tag using "value-of" XML element as a parameter Author: Craig Johnson Date: 15 Feb 2006 12:47 PM
|
Forgive my going about this all wrong, but...
I want to create what looks like a graph using data from an XML and XSL documents. I thought, well, a series of one rowed tables, having a value as the first (fixed width) column, and the "width" of the second column being equal to that value. Ok. I first started by creating an HTML document hard coding in the values, like this...
<table border="0"><tr><td width="20">158</td><td width="158" bgcolor="#009933"> </td></tr></table>
<table border="0"><tr><td width="20">39</td><td width="39" bgcolor="#999900"> </td></tr></table>
<table border="0"><tr><td width="20">320</td><td width="320" bgcolor="#009933"> </td></tr></table>
<table border="0"><tr><td width="20">36</td><td width="36" bgcolor="#999900"> </td></tr></table>
Nice enough. Ok, let me see, the XML Doc looks like this...
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="\\Webserver\c\Inetpub\wwwroot\Usagegraph.xsl"?>
<!DOCTYPE mysqldump SYSTEM "\\Webserver\c\Inetpub\wwwroot\usagegraph.dtd">
<mysqldump>
<database name="test">
<table_structure name="usagegraph">
<field Field="PlayHour" Type="int(2)" Null="YES" Key="" Extra=""/>
<field Field="Players" Type="bigint(21)" Null="NO" Key="" Default="0" Extra=""/>
<field Field="GameScores" Type="double" Null="YES" Key="" Extra=""/>
<field Field="ScorePlayer" Type="double(23,0)" Null="YES" Key="" Extra=""/>
</table_structure>
<table_data name="usagegraph">
<row>
<field name="PlayHour">0</field>
<field name="Players">4</field>
<field name="GameScores">158</field>
<field name="ScorePlayer">39</field>
</row>
<row>
<field name="PlayHour">1</field>
<field name="Players">9</field>
<field name="GameScores">320</field>
<field name="ScorePlayer">36</field>
</row>
<!-- More row(s) here -->
</table_data>
</database>
</mysqldump>
Bored yet? Anyhow, my idea was to use the values of the GameScores and ScorePlayer data to replace the hard-coded values.
I know I'm really mistreating XML, but my attempts at this approach yielded this XSL...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output version="1.0" encoding="UTF-8" indent="no" omit-xml-declaration="no" media-type="text/html"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates select="mysqldump"/>
</body>
</html>
</xsl:template>
<xsl:template match="mysqldump">
<xsl:for-each select="database">
<xsl:for-each select="table_data">
<xsl:for-each select="row">
<p><table border="1" align="left" bgcolor="#009933" >
<tr>
<td bgcolor="#9FFF66">
<xsl:value-of select="field[3]"/>
</td>
<!--<td width="<xsl:value-of select="field[3]"/>"> -->
<td width="158">
</td>
</tr>
</table>*</p>
<p><table border="1" align="left" bgcolor="#999900" >
<tr>
<td bgcolor="#9FFF66">
<xsl:value-of select="field[4]"/>
</td>
<!-- <td width="<xsl:value-of select="field[4]"/>"> -->
<td width="39">
</td>
</tr>
</table>*</p>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The commented out lines are what obviously invalidate the XSL document, but it illustrates efficiently my lack of understanding of XML and how my approach to this issue is about 90 degrees off course. I know that the second record (because of my hard coded values) is incorrectly displayed as a graph bars, but other than that, the given example produces a runnable XML document that shows 4 bars.
Get the idea? Any suggestions on a new approach? I want to use the values 158 (row1/field3), 39 (row1/field4), 320 (row2/field3), and 36 (row2/field4) as the "width" parameter of my <td>.
Thanks for taking the time to review this, and I'm open to helpful critique.
Craig
|
|
|