XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Craig JohnsonSubject: 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">&nbsp;</td></tr></table>
<table border="0"><tr><td width="20">39</td><td width="39" bgcolor="#999900">&nbsp;</td></tr></table>
<table border="0"><tr><td width="20">320</td><td width="320" bgcolor="#009933">&nbsp;</td></tr></table>
<table border="0"><tr><td width="20">36</td><td width="36" bgcolor="#999900">&nbsp;</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

Postnext
(Deleted User) Subject: HTML Tag using
Author: (Deleted User)
Date: 15 Feb 2006 01:58 PM
Hi, Craig. You need to use an attribute value template for your width attributes, using curly braces and not left and right angle brackets for the values of the width attributes.

A use case similar to yours is documented here:

http://www.stylusstudio.com/SSDN/default.asp?action=9&read=2772&fid=48

And you can learn more about attribute value templates in the XSLT specification, here:

http://www.w3.org/TR/xslt#attribute-value-templates

Finally, Mulberry Tech sponsors an XSLT forum which is a good resource for questions about XSLT usage:

http://www.mulberrytech.com/xsl/xsl-list/

Hope this helps.

David Foster
Stylus Studio Team

Postnext
Craig JohnsonSubject: HTML Tag using
Author: Craig Johnson
Date: 15 Feb 2006 03:33 PM
Thank You!!

All I needed was a nudge in thr right direction. I'll read up on these links and let you know how it goes.
Thanks again...
Craig

Posttop
Craig JohnsonSubject: HTML Tag using
Author: Craig Johnson
Date: 15 Feb 2006 09:42 PM
Here's the resulting solution for the 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" width="35" align="right">
<xsl:value-of select="field[1]"/>:00
</td>
<td width="{field[3]*.25}">
</td>
</tr>
</table><xsl:value-of select="field[3]"/></p>
<p><table border="1" align="left" bgcolor="#999900" >
<tr>
<td bgcolor="#9FFF66" width="35" align="right">
-
</td>
<td width="{field[4]*.25}">
</td>
</tr>
</table><xsl:value-of select="field[4]"/> w/<xsl:value-of select="field[2]"/> Players</p>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


The "*.25" was added to keep the graph on a reasonable size page width, and the hours were added to the first column, but it all works pretty well. Very good exercise!
Thank you everyone for your interest and assistance.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.