SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: XML and XSL

  1. #1
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML and XSL

    I am using XSL for an XML document and it isnt working. my XSL document:
    PHP Code:
    xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <
    xsl:template match="/">
        <
    html>
          <
    head>
              <
    script language="JavaScript"><xsl:comment><![CDATA[
              function 
    sort(key) {
                  var 
    document.XSLDocument.selectNodes("*/xsl:template[@match='products']//xsl:apply-templats/@order-by");
                  for (var 
    s.nextNode(); != nulls.nextNode()) {
                      
    a.value key;
                  }
                  var 
    document.XMLDocument.selectNodes("test_product_info/products");
                  
    products.innerHTML d.transformNode(document.XMLDocument);
              }
            ]]></
    xsl:comment></script>
          </head>
          <body>
            <table border="0" bgcolor="#aaaaaa">
              <tr>
                <td colspan="2">
                  <div id="products">
                    <xsl:apply-templates select="product_info/products"/>
                  </div>
                </td>
              </tr>
              <tr>
                <td align="center">
                  <a href="javascript:sort('price_per_unit')">Sort by price</a>
                </td>
                <td>
                  <a href="javascript:sort('name')">Sort by name</a>
                </td>
              </tr>
            </table>
            <p/>
          </body>
        </html>
      </xsl:template>
      <xsl:template match="products">
        <table cellspacing="0" border="0" bgcolor="#aaaaaa">
          <xsl:apply-templates select="item" order-by="name"/>
        </table>
      </xsl:template>
      <xsl:template match="item">
        <tr>
          <td><b><xsl:value-of select="name"/></b></td>
          <td>..........</td>
          <td valign="bottom"><xsl:value-of select="price_per_unit"/></td>
        </tr>
      </xsl:template>
    </xsl:stylesheet> 
    and here is my XML document
    PHP Code:
    <?xml version='1.0'?>
    <?xml
    -stylesheet type="text/xsl" href="sort.xsl"?>
    <product_info xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional">
      <products>
        <item>
          <name>Product 1</name>
          <price_per_unit currency="USD">6.50</price_per_unit>
        </item>
        <item>
          <name>Product 2</name>
          <price_per_unit currency="USD">5.00</price_per_unit>
        </item>
        <item>
          <name>Product 3</name>
          <price_per_unit currency="CD">8.25</price_per_unit>
        </item>
      </products>
    </test_product_info>
    does anyone know what could be wrong?

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    It would help to know what's not working. I'm not great at XML/XSL, but I can figure it out quicker if I know what I'm looking for...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    SitePoint Guru
    Join Date
    Sep 1999
    Location
    Singapore
    Posts
    854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One problem I could see is that your element <product_info> is closed with </test_product_info>, but I don't think that's your major problem?

  4. #4
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I forgot to post the error.

    A CDATA section was not closed. Error processing resource 'file:///C:/XML/sort.xsl'. Line 5, Position 63

    <script language="JavaScript"><xsl:comment><![CDATA[

    I also changed <product_info></product_info> and its still not working


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •