Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Table via an xsl doc

    I'm almost as sure as I can be that I have this xsl doc set up correctly. And, I'm sure I have the xml doc correct, too. All I need help with is determining where I'm going wrong connecting the two. I've Googled "tables in xml stylesheets" and things of the sort, but still I can't find where I'm going wrong. The table header prints out fine (I have the xsl doc saved as an html doc currently so I can "test" it), but that's all I'm getting. I tried href-ing to nutrition.xsl while it was saved to that, too, but it was a no go. So, I think I have everything down, just not how to connect these two. Any suggestions, if only a hint, as to where I'm going wrong? This looks like it should be MUCH easier than I'm making it.. I have an idea I shouldn't be using <xsl:for-each select=" = "whitescookie"> in the stylesheet, I've tried a couple other things too that I've found on XML tip sites... ugh... I'm getting frustrated!


    Code:
    <?xml version = "1.0"?>
    <?xml-stylesheet type = "text/xsl" href = nutrition.html"?>
    
    
    <!--Marking up documents-->
    
    
    <whitescookie>
       <serving>1 package</serving>
       <calories>260 calories</calories>
       <fatcals>100 fat calories</fatcals>
       <fat>11 g of fat</fat>
       <saturatedfat>2 g of saturated fat</saturatedfat>
       <cholesterol>5 mg of cholesterol</cholesterol>
       <sodium>210 mg of sodium</sodium>
       <carbohydrates>36 g of carbs</carbohydrates>
       <fiber>2 g of fiber</fiber>
       <sugar>15 g of sugar</sugar>
       <protein>5 g of protein</protein>
    </whitescookie>
    ...and the stylesheet "nutrition.html":



    Code:
    <?xml version = "1.0"?>
    
    <!-- XSL Stylesheet  -->
    
    <!-- reference XSL style sheet URI -->
    <xsl:stylesheet version = "1.0" 
       xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
    
       <xsl:output method = "html" omit-xml-declaration = "no" 
          doctype-system = 
             "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"
          doctype-public = "-//W3C//DTD XHTML 1.1//EN"/>
    
       <xsl:template match = "/"> 
    
       <html xmlns = "http://www.w3.org/1999/xhtml">
          <head>
             <title>Nutritional Information - Grandma White's Cookies</title>
          </head>
    
          <body>
             <table border = "1" bgcolor = "cream">
                <thead>
                   <tr>
                      <th>Nutritional Information</th>
                   </tr>
                </thead>
    
    
    	    <xsl:for-each select=" = "whitescookie">
                   <tr>
                      <td><xsl:value-of select = "@serving"/></td></tr>   
                      <td><xsl:value-of select = "@calories"/></td></tr>      
                      <td><xsl:value-of select = "@fatcals"/></td></tr>      
                      <td><xsl:value-of select = "@saturatedfat"/></td></tr>     
                      <td><xsl:value-of select = "@cholesterol"/></td></tr> 
                      <td><xsl:value-of select = "@sodium"/></td></tr>       
                      <td><xsl:value-of select = "@carbohydrates"/></td></tr>       
                      <td><xsl:value-of select = "@fiber"/></td></tr> 
                      <td><xsl:value-of select = "@sugar"/></td></tr>        
                      <td><xsl:value-of select = "@protein"/></td></tr>     
                   </tr>
                </xsl:for-each>
             </table>
          </body>
       </html>
    
       </xsl:template>
    </xsl:stylesheet>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    - missing '"' in xml
    - @ is for attributes
    - not calling anywhere xsl:apply-template
    - invalid html markup, you close a tr tag with </tr> but don't have a start tag <tr>. I remove them because was not clear for me if you want to put all on one line or not. You can put them back.

    Code:
    <?xml version = "1.0"?>
    <?xml-stylesheet type="text/xsl" href="nutrition.html"?>
    <whitescookie>
       <serving>1 package</serving>
       <calories>260 calories</calories>
       <fatcals>100 fat calories</fatcals>
       <fat>11 g of fat</fat>
       <saturatedfat>2 g of saturated fat</saturatedfat>
       <cholesterol>5 mg of cholesterol</cholesterol>
       <sodium>210 mg of sodium</sodium>
       <carbohydrates>36 g of carbs</carbohydrates>
       <fiber>2 g of fiber</fiber>
       <sugar>15 g of sugar</sugar>
       <protein>5 g of protein</protein>
    </whitescookie>
    Code:
    <?xml version = "1.0"?>
    <xsl:stylesheet version = "1.0" 
                    xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
    
      <xsl:output method="html"
                  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"
                  doctype-public="-//W3C//DTD XHTML 1.1//EN"/>
    
      <xsl:template match="/"> 
        <html>
          <head>
            <title>Nutritional Information - Grandma White's Cookies</title>
          </head>
    
          <body>
            <table border = "1" bgcolor = "cream">
              <thead>
                <tr>
                  <th>Nutritional Information</th>
                </tr>
              </thead>
                <tr>
                  <xsl:apply-templates select="whitescookie"/>
                </tr>
            </table>
          </body>
        </html>
      </xsl:template>
    
      <xsl:template match="whitescookie">
        <td>
          <xsl:value-of select = "serving"/>
        </td>
        <td>
          <xsl:value-of select = "calories"/>
        </td>
        <td>
          <xsl:value-of select = "fatcals"/>
        </td>
        <td>
          <xsl:value-of select = "saturatedfat"/>
        </td>
        <td>
          <xsl:value-of select = "cholesterol"/>
        </td>
        <td>
          <xsl:value-of select = "sodium"/>
        </td>
        <td>
          <xsl:value-of select = "carbohydrates"/>
        </td>
        <td>
          <xsl:value-of select = "fiber"/>
        </td>
        <td>
          <xsl:value-of select = "sugar"/>
        </td>
        <td>
          <xsl:value-of select = "protein"/>
        </td>
      </xsl:template>
    
    </xsl:stylesheet>
    best regards

  • Users who have thanked oesxyl for this post:

    babylikesburgh (08-22-2008)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Thumbs up

    oesxyl, you're my hero for the day ^_^

    I didn't think I was TOO far off, but had very limited resources... I think I could really handle a good ol' friend or tutor that knows their programming. Your help here allowed me to see how the code/docs tie together and now my xml doc is showing up in the format it's supposed to be showing up in No more raw-code. Thanks a bunch for your help, it would have taken me "who-knows-how-long" to keep trial-and-erroring my scipt.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by babylikesburgh View Post
    oesxyl, you're my hero for the day ^_^

    I didn't think I was TOO far off, but had very limited resources... I think I could really handle a good ol' friend or tutor that knows their programming. Your help here allowed me to see how the code/docs tie together and now my xml doc is showing up in the format it's supposed to be showing up in No more raw-code. Thanks a bunch for your help, it would have taken me "who-knows-how-long" to keep trial-and-erroring my scipt.
    now probably you can make your schema to be more restrictive and more complex if you need,

    some link that could help with xml, xslt and xpath:

    http://www.jenitennison.com/xslt/index.html

    http://www.zvon.org/xxl/XSLTreference/Output/index.html

    http://www.zvon.org/

    and of course, just ask,

    best regards

  • #5
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry

    Typo Error
    Last edited by jaci.lewis; 04-16-2009 at 03:31 AM. Reason: Typo

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    please read cf rules:

    http://www.codingforums.com/rules.htm

    regards
    Last edited by oesxyl; 04-16-2009 at 04:05 AM.

  • Users who have thanked oesxyl for this post:

    jaci.lewis (04-16-2009)


  •  

    Posting Permissions

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