markSaunders
Programmer
appologies for the size of this post, but the detail is necessary...
i want to know hoe best to use a
for the purposes described below..
i have the XML document
which is validated against the schema
which are then applied to the style sheet
.
If you cut and paste these files you would see the XML displayed in a table sorted (initially) by the refQTY field. The problem is that the sort is such that the order is...
100 -> 1000 -> 111 -> 1111 -> 113 -> 150 -> 178
i have, as you can see, declared the attribute
as fixed so thought that it would be 'treated' as such. where have i gone wrong PLEASE!!!
also if you have time to cut and paste the test any ideas why the sort function isn't working?
1. simpleXML.xml
2. simpleSchema.xsd
3. simpleXSL.xsl
Mark Saunders
i want to know hoe best to use a
Code:
DTD/SCHEMA
i have the XML document
Code:
(1)
Code:
(2)
Code:
(3)
If you cut and paste these files you would see the XML displayed in a table sorted (initially) by the refQTY field. The problem is that the sort is such that the order is...
100 -> 1000 -> 111 -> 1111 -> 113 -> 150 -> 178
i have, as you can see, declared the attribute
Code:
refQty
also if you have time to cut and paste the test any ideas why the sort function isn't working?
1. simpleXML.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="simpleXSL.xsl"?>
<recordList xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2000/10/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="simpleSchema.xsd">
<record refID="X42" refDate="04-02-01" refPrice="50.26" category="A" refName="A2 Book" refQty="100"/>
<record refID="X43" refDate="05-02-01" refPrice="556.35" category="D" refName="A3 Book" refQty="1000"/>
<record refID="X44" refDate="06-02-01" refPrice="47.89" category="D" refName="A4 Book" refQty="111"/>
<record refID="X45" refDate="06-01-01" refPrice="23.45" category="C" refName="A5 Book" refQty="1111"/>
<record refID="X46" refDate="06-02-01" refPrice="65.34" category="E" refName="A6 Book" refQty="150"/>
<record refID="X47" refDate="08-04-01" refPrice="65.12" category="D" refName="A7 Book" refQty="178"/>
<record refID="X48" refDate="01-03-01" refPrice="98.45" category="NA" refName="A8 Book" refQty="113"/>
</recordList>
2. simpleSchema.xsd
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema - Mark Saunders-->
<xsd:schema xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2000/10/XMLSchema"[/URL] elementFormDefault="qualified">
<xsd:element name="record">
<xsd:complexType>
<xsd:attribute name="refID" type="xsd:string" use="required"/>
<xsd:attribute name="refDate" type="xsd:date" use="required"/>
<xsd:attribute name="refName" type="xsd:string" use="optional"/>
<xsd:attribute name="refQty" type="xsd:decimal" use="default" value="100"/>
<xsd:attribute name="refPrice" type="xsd:decimal" use="required"/>
<xsd:attribute name="category" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
<xsd:enumeration value="D"/>
<xsd:enumeration value="E"/>
<xsd:enumeration value="NA"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="recordList">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="record" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
3. simpleXSL.xsl
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/TR/WD-xsl">[/URL]
<xsl:template match="/">
<html>
<head></head>
<SCRIPT LANGUAGE="VBScript"><xsl:comment><![CDATA[
Dim stylesheet, source, sortField
Function sort(field)
sortField.value = "@" + field
listing.innerHTML = source.documentElement.transformNode(stylesheet)
End Function
]]></xsl:comment></SCRIPT>
<SCRIPT LANGUAGE="VBScript" for="window" event="onload"><xsl:comment><![CDATA[
Set stylesheet = document.XSLDocument
Set source = document.XMLDocument
Set sortField = document.XSLDocument.selectSingleNode("//@order-by")
]]></xsl:comment></SCRIPT>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<DIV id="listing">
<xsl:apply-templates select="recordList"/>
</DIV>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="recordList">
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr bgcolor="navy" style="color:white;font-size:8pt;font-family:Tahoma;font-weight:bold" class="header">
<td onclick="sort('refID')">refID</td>
<td onclick="sort('refDate')">refDate</td>
<td onclick="sort('refPrice')">refPrice</td>
<td onclick="sort('category')">category</td>
<td onclick="sort('refName')">refName</td>
<td onclick="sort('refQty')">refQty</td>
</tr>
<xsl:for-each order-by="+ @refQty" select="record">
<tr bgcolor="#F0F0FF" style="color:black;font-size:8pt;font-family:Tahoma">
<td><xsl:value-of select="@refID"/></td>
<td><xsl:value-of select="@refDate"/></td>
<td><xsl:value-of select="@refPrice"/></td>
<td><xsl:value-of select="@category"/></td>
<td><xsl:value-of select="@refName"/></td>
<td><xsl:value-of select="@refQty"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>