Web Services, Part VIII: Reading DTDs with JavaScript: Code Listings - Doc JavaScript
Web Services, Part VIII: Reading DTDs with JavaScript
Code Listings
Here is the listing ofmydvd7.xml
:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="mydvd7.xsl"?> <!DOCTYPE sales SYSTEM "mydvd7.dtd"> <sales> <summary> <heading>MyDVD Rental Store</heading> <subhead>Periodical Sales Report</subhead> <description>Sales Report for January, February, and <&month;> of 2001</description> <author>author: &preparedby;</author> <date>Jan 30, 2002</date> </summary> <data> <month> <name>January 2001</name> <week number="1" dvds_rented="12000" /> <week number="2" dvds_rented="15000" /> <week number="3" dvds_rented="18000" /> <week number="4" dvds_rented="11800" /> </month> <month> <name>February 2001</name> <week number="1" dvds_rented="11500" /> <week number="2" dvds_rented="12390" /> <week number="3" dvds_rented="19050" /> <week number="4" dvds_rented="11200" /> </month> <month> <name>March 2001</name> <week number="1" dvds_rented="15300" /> <week number="2" dvds_rented="12390" /> <week number="3" dvds_rented="10050" /> <week number="4" dvds_rented="11230" /> </month> </data> </sales>
Here is the listing of mydvd7.dtd
:
<!ELEMENT sales (summary, data)> <!ELEMENT summary (heading, subhead, description, author, date)> <!ELEMENT heading (#PCDATA)> <!ELEMENT subhead (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT date (#PCDATA)> <!ELEMENT data (month*)> <!ELEMENT month (name, week*)> <!ELEMENT name (#PCDATA)> <!ELEMENT week (#PCDATA)> <!ATTLIST week number CDATA #REQUIRED> <!ATTLIST week dvds_rented CDATA #REQUIRED> <!ENTITY preparedby "John Smith"> <!ENTITY month "April"> <!ENTITY day "Wednesday, ">
Finally, here is the listing of mydvd7.xsl
:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:param name="forecast" select="50000"/> <xsl:param name="weekly_quota" select="12000"/> <xsl:template match="/"> <HTML> <HEAD> <TITLE><xsl:value-of select="//summary/heading"/></TITLE> </HEAD> <BODY> <H1><xsl:value-of select="//summary/heading"/></H1> <H2><xsl:value-of select="//summary/subhead"/></H2> <P><xsl:value-of select="//summary/description"/></P> <P><xsl:value-of select="//summary/author"/></P> <TABLE> <TR> <TH>Month\Week</TH> <xsl:for-each select="//data/month[1]/week"> <TH>W<xsl:value-of select="@number"/></TH> </xsl:for-each> <TH>Total</TH> <TH>Forecast</TH> </TR> <xsl:for-each select="//data/month"> <tr> <th style="text-align:left"><xsl:value-of select="name"/></th> <xsl:for-each select="week"> <td> <xsl:attribute name="style"> <xsl:choose> <xsl:when test="number(@dvds_rented <= $weekly_quota)">color:red;</xsl:when> <xsl:otherwise>color:green;</xsl:otherwise> </xsl:choose> text-align:right; </xsl:attribute> <xsl:value-of select="format-number(@dvds_rented, '###,###')"/> </td> </xsl:for-each> <td style="text-align:right;font-weight:bold"> <xsl:value-of select="format-number(sum(week/@dvds_rented), '###,###')"/> </td> <td style="text-align:right;font-weight:bold"> <xsl:value-of select="format-number($forecast, '###,###')"/> </td> </tr> </xsl:for-each> </TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet>
Next: A Final Word
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 11, 2002
Revised: February 11, 2002
URL: https://www.webreference.com/js/column103/8.html