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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + First time to Stylus Studio 20... (3)
-> + xsl:if test statement result t... (4)
-> + XSLT for dynamic target fields (4)
-> + Remove duplicates (2)
-> + XML-XSL grouping issue while d... (2)
-> + Two XML files. Two Tables. One... (3)
-> + Saxon 9.3 with XSLV (2)
-> - How do I remove the text strin... (1)
-> + Xpath of each element (3)
-> + Attributes - required vs optio... (2)
-> + XML schema to XML schema with ... (2)
-> + how to preserve the & in X... (2)
-> + how to use variables within (2)
-> + need help in XSLT programming (3)
-> + XSLT Mapper Option... Where i... (3)
-> - Selecting element based on att... (1)
-> + replace question (2)
-> - select other node based on one... (1)
-> - XSLT question... (1)
-> - Mapper and XSL (1)
-> - Copying XML as is with one cha... (1)
-> - Help with XSLT (1)
-> - XSL repeat the parent node for... (1)
-> - xls to xml (1)
-> - Stylus support non-backreferen... (1)
-> - Assigning records to existing ... (1)
-> + xsl:for-each and key() (2)
-> + tags containing a: (2)
-> - Create a namespace in output f... (1)
-> - XML Converters problem on UNIX (1)
-> - Copy XML Based on IF Condition... (1)
-> - csv counting dependencies (1)
-> + For extension function, could ... (2)
-> - XML XSLT Transformation (1)
-> + Transform XSD to another XSD (3)
-> - New to Stylus (1)
-> + my enterprise install doesn't ... (2)
-> - Replace line in XML (1)
-> - 5010 HIPAA - Example EDI files... (1)
-> - Display table in two columns f... (1)
-> + java.lang.RuntimeException (4)
-> + Select Value-Of Qualified Elem... (2)
-> + Validating different sets of r... (2)
-> + Passing complete source docume... (2)
-> - XSLT to sort XML per schema (1)
-> - XSL to select the group of row... (1)
-> + first ancestor of a type (2)
-> - Column Width Adjustment (1)
-> + XSLT breakpoint being ignored ... (6)
-> - Creating a tab delimited file (1)
-> - Invalid characters in xml (1)
-> + Creating XSLT File Based on XS... (2)
-> - Unable to filter InputStream f... (1)
-> + finding a list of values (7)
-> - TEMP directory question (1)
-> - [HELP] Template and namespace (1)
-> - The prefix "xsl" for element "... (1)
-> - Need help comparing dates in x... (1)
-> - trying to sort a list of artic... (1)
-> + Count unique values using XSLT (3)
-> + Dot "." vs. self::node() (2)
-> + Output from report and XSL do ... (2)
-> + XSL report (2)
-> + cannot see valid values in the... (2)
-> - sum function help (1)
-> + XSLT transformation problem (2)
-> + Flat To nested XML using Keys (3)
-> - XSLT Editor autocomplete funct... (1)
-> - Receiving an argument from a l... (1)
-> + Can't using the Xalan-J in Sty... (2)
-> + Need help testing to see if th... (2)
-> + Any good way to handle repeati... (2)
-> - Renaming child element name wh... (1)
-> + What to do to only how last 4 ... (2)
-> + Help to access an element with... (3)
-> - Multiplication for-each (1)
-> - XSL / X-Path query (1)
-> - Help in creating XSD (1)
-> + JAVASCRIPT Inside XSL (2)
-> + is at possible to create edita... (2)
-> + Grouping on Multiple Field (2)
-> + XSLT 1.0 Grouping Small change... (2)
-> + Revision bar based on the page... (2)
-> + xslt to rtf (2)
-> + XEP/FOP Error (3)
-> + XML to XML Transformation (3)
-> + This XSLT has stumped me.. (2)
-> + converting XML to EACOM format (2)
-> + Stylus with XSLT 1.0 + EXSLT T... (2)
-> + Xslt Mapper (2)
-> - xml to xsl (1)
-> - creating a website (1)
-> - XML to PDF using XML Publisher... (1)
-> - Replace nodes (1)
-> - New to XSLT, need help with a ... (1)
-> - Modify XSLT - Have List of Cha... (1)
-> - Replace nodes in one xml file ... (1)
-> - Alternate Row Colour (1)
-> - convert text to XML and then m... (1)
-> - CDATA to XML - work with trans... (1)
-- Previous [61-80] [81-100] [101-120] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.