Ok I am having trouble with this homework assignment. I need to modify the code to sort by the number of pages rather than by chapte number. I get this part but the code I need to modify will not display correctly in my internet browser. All I see is my code and never the image it is meant to display. Here is the code.

.xml code

<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "sorting.xsl"?>

<!-- Fig. 15.20 sorting.xml -->
<!-- XML document containing book information -->
<book isbn = "999-99999-9-X">
   <title>Deitel&apos;s XML Primer</title>

   <author>
      <firstName>Jane</firstName>
      <lastName>Blue</lastName>
   </author> <chapters>
      <frontMatter>
         <preface pages = "2" />
         <contents pages = "5" />
         <illustrations pages = "4" />
      </frontMatter>

      <chapter number = "3" pages = "44">Advanced XML</chapter>
      <chapter number = "2" pages = "35">Intermediate XML</chapter>
      <appendix number = "B" pages = "26">Parsers and Tools</appendix>
      <appendix number = "A" pages = "7">Entities</appendix>
      <chapter number = "1" pages = "28">XML Fundamentals</chapter>
   </chapters>

   <media type = "CD" />
</book>

<!-- 

.xsl code

<?xml version = "1.0"?>

<!-- Fig. 15.21: sorting.xsl -->
<!-- Transformation of book information into HTML5 -->
<xsl:stylesheet version = "1.0"                       
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

   <!-- write XML declaration and DOCTYPE DTD information -->
   <xsl:output method = "html" doctype-system = "about:legacy-compat" />

   <!-- match document root -->
   <xsl:template match = "/">  
      <html>
         <xsl:apply-templates/>
      </html>
   </xsl:template>

   <!-- match book -->          
   <xsl:template match = "book">
      <head>
         <meta charset = "utf-8"/>
         <link rel = "stylesheet" type = "text/css" href = "style.css"/>
         <title>ISBN <xsl:value-of select = "@isbn"/> - 
            <xsl:value-of select = "title"/></title>    
      </head>

      <body>
         <h1><xsl:value-of select = "title"/></h1>
         <h2>by 
            <xsl:value-of select = "author/lastName"/>,     
            <xsl:value-of select = "author/firstName"/></h2>

         <table>

            <xsl:for-each select = "chapters/frontMatter/*">
               <tr>
                  <td>
                     <xsl:value-of select = "name()"/>
                  </td>

                  <td>
                     ( <xsl:value-of select = "@pages"/> pages )
                  </td>
               </tr>
            </xsl:for-each>

            <xsl:for-each select = "chapters/chapter">
               <xsl:sort select = "@number" data-type = "number" 
                    order = "ascending"/>                        
               <tr>
                  <td>
                     Chapter <xsl:value-of select = "@number"/>
                  </td>

                  <td>
                     <xsl:value-of select = "text()"/>
                     ( <xsl:value-of select = "@pages"/> pages )
                  </td>
               </tr>
            </xsl:for-each>

            <xsl:for-each select = "chapters/appendix">
               <xsl:sort select = "@number" data-type = "text" 
                  order = "ascending"/>                        
               <tr>
                  <td>
                     Appendix <xsl:value-of select = "@number"/>
                  </td>

                  <td>
                     <xsl:value-of select = "text()"/>
                     ( <xsl:value-of select = "@pages"/> pages )
                  </td>
               </tr>
            </xsl:for-each>
         </table>

         <p>Pages: 
            <xsl:variable name = "pagecount"       
               select = "sum(chapters//*/@pages)"/>
            <xsl:value-of select = "$pagecount"/></p> 
         <p>Media Type: <xsl:value-of select = "media/@type"/></p>
      </body>
   </xsl:template>
</xsl:stylesheet> <chapters>
      <frontMatter>
         <preface pages = "2" />
         <contents pages = "5" />
         <illustrations pages = "4" />
      </frontMatter>

      <chapter number = "3" pages = "44">Advanced XML</chapter>
      <chapter number = "2" pages = "35">Intermediate XML</chapter>
      <appendix number = "B" pages = "26">Parsers and Tools</appendix>
      <appendix number = "A" pages = "7">Entities</appendix>
      <chapter number = "1" pages = "28">XML Fundamentals</chapter>
   </chapters>

   <media type = "CD" />
</book>

<!-- 

How do I get this code to properly render the image that I need?

Member Avatar for LastMitch

Ok I am having trouble with this homework assignment. I need to modify the code to sort by the number of pages rather than by chapte number. I get this part but the code I need to modify will not display correctly in my internet browser. All I see is my code and never the image it is meant to display.

@ncis_sg1

Even if this is your homework assignment how can you now understand this assignmen.t If you want xml list to display a image then you need to put the link on the xml file in

for example:

<firstName>Jane</firstName>

Let's used that as an example now I add a link:

<image:image>
 <image:loc>http://daniweb.com/image.jpg</image:loc>
</image:image>

now when you upload that xml with the path to that image that link will appear.

when you used xml files it's just data and you can used it as a sitemap.

This is my answer to your question and I am a bit curious what you did to solve your question. It would be nice if you can share how you did it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.