title: Using XSL to sort XML data then output an XML file to be read by Classic ASP
body: <p>Hopefully this will be a simple fix. I'm completely new to XSL but I've managed to get a little script that sorts my data by date. I now want to use ASP to limit this data to all entries within a month (this works by using a DateDiff() function). When I go to load in the XSL scripts output it says that my XML is malformed. Can anyone help me out here please?</p>
  
  <p>Here's my XML File:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Rota&gt;
     &lt;Shift&gt;
        &lt;date&gt;23/07/2010&lt;/date&gt;
        &lt;title1&gt;GM Neurosciences&lt;/title1&gt;
        &lt;gm&gt;Katie Cusick&lt;/gm&gt;
        &lt;title2&gt;Chief Operating Officer&lt;/title2&gt;
        &lt;director&gt;Patrick Mitchell&lt;/director&gt;
        &lt;nurse&gt;n/a&lt;/nurse&gt;
      &lt;/Shift&gt;
      &lt;Shift&gt;
        &lt;date&gt;30/07/2010&lt;/date&gt;
        &lt;title1&gt;GM Specialised Medicine&lt;/title1&gt;
        &lt;gm&gt;Alison Watson&lt;/gm&gt;
        &lt;title2&gt;DDO Medicine &amp;amp; Cardio.&lt;/title2&gt;
        &lt;director&gt;Suzanne Marsello&lt;/director&gt;
        &lt;nurse&gt;n/a&lt;/nurse&gt;
      &lt;/Shift&gt;
  &lt;/Rota&gt;
  </code></pre>
  
  <p>Here's my XSL File:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
     &lt;xsl:output method="xml" omit-xml-declaration="no" version="1.0" /&gt;
     &lt;xsl:param name="sortBy" select="'date'"/&gt;
     &lt;xsl:param name="strXPath" select="//Shift"/&gt;
     &lt;xsl:template match="/"&gt; 
        &lt;xsl:apply-templates select="$strXPath"&gt;
                 &lt;xsl:sort select="substring(date,7,4)"/&gt; &lt;!-- year sort --&gt;
                 &lt;xsl:sort select="substring(date,4,2)"/&gt; &lt;!-- month sort --&gt;  
                 &lt;xsl:sort select="substring(date,1,2)"/&gt; &lt;!-- day sort --&gt;
            &lt;/xsl:apply-templates&gt;
     &lt;/xsl:template&gt;
     &lt;xsl:template match="Shift"&gt; 
         &lt;Shift&gt;
             &lt;date&gt;&lt;xsl:value-of select="date"/&gt;&lt;/date&gt;
             &lt;title1&gt;&lt;xsl:value-of select="title1"/&gt;&lt;/title1&gt;
             &lt;gm&gt;&lt;xsl:value-of select="gm"/&gt;&lt;gm&gt;
             &lt;title2&gt;&lt;xsl:value-of select="title2"/&gt;&lt;/title2&gt;
             &lt;director&gt;&lt;xsl:value-of select="director"/&gt;&lt;/director&gt;
             &lt;nurse&gt;&lt;xsl:value-of select="nurse"/&gt;&lt;/nurse&gt;
         &lt;/Shift&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And Here's my ASP Code:</p>
  
  <pre><code>&lt;%
  
  Set entries = Server.CreateObject("Microsoft.XMLDOM")
  Set entry = Server.CreateObject("Microsoft.XMLDOM")
  Set xml = Server.CreateObject("Microsoft.XMLDOM")
  Set xsl = Server.CreateObject("Microsoft.XMLDOM")
  Set newxml = Server.CreateObject("Microsoft.XMLDOM")
  
  xml.async = False
  xml.load (Server.MapPath("rota.xml"))
  
  xsl.async = False
  xsl.load(Server.MapPath("indexrota.xsl"))
  newxml.async = False
  newxml.load(xml.transformNode(xsl))
  
  set entries = newxml.getElementsbyTagName("Shift")
  noOfEntries = entries.length
  startDate = "15/07/2010"
  LastDate = DateAdd("m",1,date())
  
  
  Response.Write("&lt;table&gt;&lt;tr&gt;&lt;th&gt;Date&lt;/th&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;GM&lt;/th&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Director&lt;/th&gt;&lt;th&gt;Nurse / Matron&lt;/th&gt;&lt;/tr&gt;")
  For i = 0 To (noOfEntries - 1)
      Set entry = entries.item(i)
      If isDate(entry.childNodes(0).text) Then
          meh = CDate(entry.childNodes(0).text)
          beginning = DateDiff("d", meh, startDate)
          ended = DateDiff("d", meh, LastDate)
          If beginning + 1 &lt;= 0 And ended &gt;= 0 Then
              Response.Write("&lt;tr&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(0).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(1).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(2).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(3).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(4).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;td&gt;" &amp; entry.childNodes(5).text &amp; "&lt;/td&gt;"&amp;_
              "&lt;/tr&gt;")
              End If
          End If
      Next
      Response.Write("&lt;/table&gt;")
  %&gt;
  </code></pre>
  
  <p>I'm sure it's a case of the XSL because the ASP has worked perfecton the XML before</p>