Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with DTD or SCHEMA..

Status
Not open for further replies.

markSaunders

Programmer
Jun 23, 2000
196
GB
appologies for the size of this post, but the detail is necessary...

i want to know hoe best to use a
Code:
DTD/SCHEMA
for the purposes described below..

i have the XML document
Code:
(1)
which is validated against the schema
Code:
(2)
which are then applied to the style sheet
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
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
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;simpleXSL.xsl&quot;?>
<recordList xmlns:xsi=&quot;[URL unfurl="true"]http://www.w3.org/2000/10/XMLSchema-instance&quot;[/URL] xsi:noNamespaceSchemaLocation=&quot;simpleSchema.xsd&quot;>
  <record refID=&quot;X42&quot; refDate=&quot;04-02-01&quot; refPrice=&quot;50.26&quot; category=&quot;A&quot; refName=&quot;A2 Book&quot; refQty=&quot;100&quot;/>
  <record refID=&quot;X43&quot; refDate=&quot;05-02-01&quot; refPrice=&quot;556.35&quot; category=&quot;D&quot; refName=&quot;A3 Book&quot; refQty=&quot;1000&quot;/>
  <record refID=&quot;X44&quot; refDate=&quot;06-02-01&quot; refPrice=&quot;47.89&quot; category=&quot;D&quot; refName=&quot;A4 Book&quot; refQty=&quot;111&quot;/>
  <record refID=&quot;X45&quot; refDate=&quot;06-01-01&quot; refPrice=&quot;23.45&quot; category=&quot;C&quot; refName=&quot;A5 Book&quot; refQty=&quot;1111&quot;/>
  <record refID=&quot;X46&quot; refDate=&quot;06-02-01&quot; refPrice=&quot;65.34&quot; category=&quot;E&quot; refName=&quot;A6 Book&quot; refQty=&quot;150&quot;/>
  <record refID=&quot;X47&quot; refDate=&quot;08-04-01&quot; refPrice=&quot;65.12&quot; category=&quot;D&quot; refName=&quot;A7 Book&quot; refQty=&quot;178&quot;/>
  <record refID=&quot;X48&quot; refDate=&quot;01-03-01&quot; refPrice=&quot;98.45&quot; category=&quot;NA&quot; refName=&quot;A8 Book&quot; refQty=&quot;113&quot;/>
</recordList>

2. simpleSchema.xsd
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<!--W3C Schema - Mark Saunders-->
<xsd:schema xmlns:xsd=&quot;[URL unfurl="true"]http://www.w3.org/2000/10/XMLSchema&quot;[/URL] elementFormDefault=&quot;qualified&quot;>
  <xsd:element name=&quot;record&quot;>
    <xsd:complexType>
      <xsd:attribute name=&quot;refID&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;/>
      <xsd:attribute name=&quot;refDate&quot; type=&quot;xsd:date&quot; use=&quot;required&quot;/>
      <xsd:attribute name=&quot;refName&quot; type=&quot;xsd:string&quot; use=&quot;optional&quot;/>
      <xsd:attribute name=&quot;refQty&quot; type=&quot;xsd:decimal&quot; use=&quot;default&quot; value=&quot;100&quot;/>
      <xsd:attribute name=&quot;refPrice&quot; type=&quot;xsd:decimal&quot; use=&quot;required&quot;/>
      <xsd:attribute name=&quot;category&quot; use=&quot;optional&quot;>
        <xsd:simpleType>
          <xsd:restriction base=&quot;xsd:NMTOKEN&quot;>
            <xsd:enumeration value=&quot;A&quot;/>
            <xsd:enumeration value=&quot;B&quot;/>
            <xsd:enumeration value=&quot;C&quot;/>
            <xsd:enumeration value=&quot;D&quot;/>
            <xsd:enumeration value=&quot;E&quot;/>
            <xsd:enumeration value=&quot;NA&quot;/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:attribute>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name=&quot;recordList&quot;>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref=&quot;record&quot; maxOccurs=&quot;unbounded&quot;/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

3. simpleXSL.xsl
Code:
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/TR/WD-xsl&quot;>[/URL]
  <xsl:template match=&quot;/&quot;>
    <html>
      <head></head>
        <SCRIPT LANGUAGE=&quot;VBScript&quot;><xsl:comment><![CDATA[
          Dim stylesheet, source, sortField
          Function sort(field)
            sortField.value = &quot;@&quot; + field
            listing.innerHTML = source.documentElement.transformNode(stylesheet)
          End Function
        ]]></xsl:comment></SCRIPT>
        <SCRIPT LANGUAGE=&quot;VBScript&quot; for=&quot;window&quot; event=&quot;onload&quot;><xsl:comment><![CDATA[
          Set stylesheet = document.XSLDocument
          Set source = document.XMLDocument
          Set sortField = document.XSLDocument.selectSingleNode(&quot;//@order-by&quot;)
        ]]></xsl:comment></SCRIPT>
      <body>
        <table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
          <DIV id=&quot;listing&quot;>
            <xsl:apply-templates select=&quot;recordList&quot;/> 
          </DIV>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match=&quot;recordList&quot;>
    <table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; width=&quot;100%&quot;>
      <tr bgcolor=&quot;navy&quot; style=&quot;color:white;font-size:8pt;font-family:Tahoma;font-weight:bold&quot; class=&quot;header&quot;>
        <td onclick=&quot;sort('refID')&quot;>refID</td>
        <td onclick=&quot;sort('refDate')&quot;>refDate</td>
        <td onclick=&quot;sort('refPrice')&quot;>refPrice</td>
        <td onclick=&quot;sort('category')&quot;>category</td>
        <td onclick=&quot;sort('refName')&quot;>refName</td>
        <td onclick=&quot;sort('refQty')&quot;>refQty</td>
      </tr>

      <xsl:for-each order-by=&quot;+ @refQty&quot; select=&quot;record&quot;>
        <tr bgcolor=&quot;#F0F0FF&quot; style=&quot;color:black;font-size:8pt;font-family:Tahoma&quot;>
          <td><xsl:value-of select=&quot;@refID&quot;/></td>
          <td><xsl:value-of select=&quot;@refDate&quot;/></td>
          <td><xsl:value-of select=&quot;@refPrice&quot;/></td>
          <td><xsl:value-of select=&quot;@category&quot;/></td>
          <td><xsl:value-of select=&quot;@refName&quot;/></td>
          <td><xsl:value-of select=&quot;@refQty&quot;/></td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>
Mark Saunders :)
 
just seen how messy this post is when looking at the code - best bet is to cut n paste the code into note pad and extend to full width of screen. - i realise it's a bit of a pain, but i suspect a number of people will benefit from knowing how best to use schemas etc for formatting data..

also, (well there's nothing like cheek is there) is it possible to populate a combo box (say, on a form) from the enumerated values of a restriction. Mark Saunders :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top