Loading ...
Sorry, an error occurred while loading the content.

sort and display book author when book has multiple authors

Expand Messages
  • no1_charlie_chan
    A NEWBIE HERE WITH A DO-IT-YOURSELF LEARNING PROJECT I can easly sort the books in my library xml document by title and subject because there is only one
    Message 1 of 1 , Apr 2, 2005
    • 0 Attachment
      A NEWBIE HERE WITH A DO-IT-YOURSELF LEARNING PROJECT
      I can easly sort the books in my library xml document by title and
      subject because there is only one element each for a book. What I can
      not do is sort the authors and display each author followed by the
      book title, authors, publisher, etc. The following code will only
      display the first table which informs the user of the sortation mode
      and provides links to diplay a title and subject sortation options.
      Will someone please help me over this hurdle. Here are the documents
      for this learning project I created. The problem is with the file
      named BooksTransform_author.xsl.

      My_Books_author.xml
      <?xml version="1.0" ?>
      <?xml-stylesheet href="BooksTransform_author.xsl" type="text/xsl" ?>
      <data>
      <item>
      <title>JavaScript Unleashed</title>
      <edition>Third Edition</edition>
      <copyright>2000</copyright>
      <author>Richard Wagner</author>
      <author>R. Allen Wyke</author>
      <publisher>SAMS</publisher>
      <isbn>0-672-31763-X</isbn>
      <lccn>99-63993</lccn>
      <price>$49.99 USD</price>
      <subject>JavaScript Scripting Language - Much of this is
      about how to embed JavaScript into HTML:
      client-side, server-side, and Microsoft Active Server Pages
      (ASP).</subject>
      </item>

      <item>
      <title>1001 Visual Basic Programmer's Tips</title>
      <edition>First Edition</edition>
      <copyright>1997</copyright>
      <author>Kris Jamsa, Ph.D.</author>
      <author>Lars Klander</author>
      <publisher>Jamsa Press</publisher>
      <isbn>1-884133-56-8</isbn>
      <lccn></lccn>
      <price>$54.95 USD</price>
      <subject>Visual Basic 5 Programming Language - It is for the
      first time VB Programmer
      or the expert. It covers manipulating ActiverX controls, documents,
      libraries, and servers. Talks about VBScript.</subject>
      </item>

      <item>
      <title>HTlML 4</title>
      <edition>Second Edition</edition>
      <copyright>1999</copyright>
      <author>Deborah S. Ray</author>
      <author>Eric J. Ray</author>
      <publisher>SYBEX</publisher>
      <isbn>0-7821-2523-9</isbn>
      <lccn>99-661301</lccn>
      <price>$34.99 USD</price>
      <subject>HyperText Markup Language 4 - "... your one-stop
      comprehensive guide to HyperText
      Markup Language?"</subject>
      </item>

      <item>
      <title>Beginning Visual C++ 6</title>
      <edition>Third Edition</edition>
      <copyright>1998</copyright>
      <author>Ivor Horton</author>
      <publisher>Wrox Press Ltd.</publisher>
      <isbn>1-861000-88-X</isbn>
      <lccn></lccn>
      <price>$49.99 USD</price>
      <subject>Visual C++ 6 - from beginner level to building
      an actual, though limited, working Windows program using
      Microsoft Foundation Classes. It is a difficult book!</subject>
      </item>

      <item>
      <title>Learn to Program with C++</title>
      <edition>First Edition</edition>
      <copyright>2002</copyright>
      <author>John Smiley</author>
      <publisher>M cGraw-Hill/Osborne</publisher>
      <isbn>0-07-222535-1</isbn>
      <lccn></lccn>
      <price>$29.99 USD</price>
      <subject>C++ Programming Language - This an excellent book for the
      true begin to start learning C++.</subject>
      </item>

      <item>
      <title>Teach Yourself C</title>
      <edition>Third Edition</edition>
      <copyright>1997</copyright>
      <author>Herbert Schildt</author>
      <publisher>Osborne McGraw-Hill</publisher>
      <isbn>0-07-882311-0</isbn>
      <lccn></lccn>
      <price>$27.99 USD</price>
      <subject>C Programming Language - "Herb Schildt tells his programmers
      what they want and need to
      know-- simply, clearly, concisely, and authoritatively". -- ACM
      Computer Reviews</subject>
      </item>

      <item>
      <title>Visual Basic 6 COMPLETE</title>
      <edition>First Edition</edition>
      <copyright>1999</copyright>
      <author>Steve Brown</author>
      <author>Wayne S. Freeze</author>
      <author>Ken Getz</author>
      <author>Mike Gilbert</author>
      <author>Guy Hart-Davis</author>
      <author>Kevin Hough</author>
      <author>Susann Novalis</author>
      <author>Evangelos Petroutsos</author>
      <publisher>SYBEX Inc.</publisher>
      <isbn>0-7821-2469-0</isbn>
      <lccn>99-61303</lccn>
      <price>$19.99 USD</price>
      <subject>Visual Basic 6 Programming Language - complete reference,
      Visual Basic 6 function reference,
      intro to VBA, practical VB 6 examples, debugging info, mastering the
      IDE, etc</subject>
      </item>

      <item>
      <title>PURE JavaScript</title>
      <edition>Second Edition</edition>
      <copyright>2002</copyright>
      <author>R. Allen Wyke</author>
      <author>Jason D. Gilliam</author>
      <author>Charlton Ting</author>
      <author>Sean Michaels</author>
      <publisher>SAMS</publisher>
      <isbn>0-672-32141-6</isbn>
      <lccn>00-11512</lccn>
      <price>$49.99 USD</price>
      <subject>JavaScript Scripting Language Reference - A code-intensive
      premium reference book</subject>
      </item>

      <item>
      <title>Visual Basic 6 Core Language Little Black Book</title>
      <edition>First Edition</edition>
      <copyright>1999</copyright>
      <author>Steven Holzner</author>
      <publisher>The Coriolis Group</publisher>
      <isbn>1-57610-390-0</isbn>
      <lccn></lccn>
      <price>$24.99 USD</price>
      <subject>Visual Basic 6 Programming Language - "Indispensable Problem
      Solver"</subject>
      </item>

      <item>
      <title>Win32 API Programming with Visual Basic</title>
      <edition>First Edition</edition>
      <copyright>2000</copyright>
      <author>Steven Roman</author>
      <publisher>O'Reilly</publisher>
      <isbn>1-56592-631-5</isbn>
      <lccn></lccn>
      <price>$39.95 USD</price>
      <subject>Visual Basic and Win32 APIs - Taking Advantage of Windows
      System Services with VB It lists my of the
      Windows APIs.</subject>
      </item>
      </data>
      ---------------------------------------------------------------

      BooksTransform_author.xsl
      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes" />

      <xsl:param name="aBook" select="data/item" />
      <xsl:variable name="aAuthor" select="data/item/author" />

      <xsl:template match="/">
      <html>
      <body>
      <table>
      <!-- The is the Sortation Option section. -->
      <tr><td align="left"> Books Sorted by Author </td><td align="left">
      Sort By: </td><td><a href="My_Books_title.xml" > Title </a>
      </td><td> or </td><td><a href="My_Books_main.xml"> Subject
      </a></td></tr>
      </table>

      <xsl:for-each select="data/item/author">
      <xsl:for-each select="item">
      <xsl:for-each select="author">
      <xsl:if test="aAuthor" />
      <table border="4" bordercolor="#888888" >
      <xsl:apply-templates select="." />
      </table>
      </xsl:for-each>
      </xsl:for-each>

      </xsl:for-each>
      </body>
      </html>
      </xsl:template>


      <xsl:template match="/item">
      <xsl:for-each select="author">
      <tr><td>AUTHOR/s</td><td><xsl:value-of select="." /></td></tr>
      </xsl:for-each>
      <tr bgcolor="beige"><td>TITLE</td><xsl:element
      name="td"><xsl:value-of select="title" /></xsl:element></tr>
      <tr><td>EDITION</td><td><xsl:value-of select="edition" /></td></tr>
      <tr><td>PUBLISHER</td><td><xsl:value-of select="publisher" /></td></tr>
      <tr><td>ISBN</td><td><xsl:value-of select="isbn" /></td></tr>
      <tr><td>LCCN</td><td><xsl:value-of select="lccn" /></td></tr>
      <tr><td>PRICE</td><td><xsl:value-of select="price" /></td></tr>
      <tr><td>SUBJECT</td><td><p><xsl:value-of select="subject"
      /></p></td></tr>

      </xsl:template>
      </xsl:stylesheet>
      ------------------------------------------------------

      My_Books_main.xml
      <?xml version="1.0" ?>
      <?xml-stylesheet href="BooksTransform_subject.xsl" type="text/xsl" ?>
      <data>same information that is in My_Books_author.xml</data>
      ---------------------------------------------------------

      My_Books_title.xml
      <?xml version="1.0" ?>
      <?xml-stylesheet href="BooksTransform_title.xsl" type="text/xsl" ?>
      <data> same information that is in My_Books_author.xml</data>
      -------------------------------------------------

      BooksTransform_subject.xsl
      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes" />
      <xsl:template match="/">
      <html>
      <link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
      <head>
      <!-- This sends the title and number of books to the Title bar. -->
      <title>My Library - which contains <xsl:value-of
      select="count(/data/item)" /> books</title>
      </head>
      <body>
      <table>
      <!-- The is the Sortation Option section. -->
      <tr><td align="left"> Books Sorted by Subject </td><td align="left">
      Sort By: </td><td><a href="My_Books_title.xml" > Title </a></td><td>
      or </td><td><a href="My_Books_author.xml"> Author </a></td></tr>
      </table>
      <!-- This contains a for-each loop used to loop through the XML data,
      sort it by subject,
      and place each itiem in it own HTML formatted table -->
      <xsl:for-each select="data/item">
      <xsl:sort select="normalize-space(subject)" />
      <table border="4" bordercolor="#888888" ><!-- border color to dark
      gray -->
      <xsl:apply-templates select="." /><!-- the dot stops it from
      reprinting the 1st item count times -->
      </table>
      </xsl:for-each>
      </body>
      </html>
      </xsl:template>

      <!-- This template displays the XML date in table rows and table data
      units. It also
      has a for-each loop that display one or more authors according to the
      book data being parsed. -->
      <xsl:template match="/data/item">
      <tr bgcolor="beige"><td>TITLE</td><td><xsl:value-of select="title"
      /></td></tr>
      <tr><td>EDITION</td><td><xsl:value-of select="edition" /></td></tr>
      <!-- for-each loop -->
      <xsl:for-each select="author">
      <tr><td>AUTHOR/s</td><td><xsl:value-of select="." /></td></tr>
      </xsl:for-each>
      <tr><td>PUBLISHER</td><td><xsl:value-of select="publisher" /></td></tr>
      <tr><td>ISBN</td><td><xsl:value-of select="isbn" /></td></tr>
      <tr><td>LCCN</td><td><xsl:value-of select="lccn" /></td></tr>
      <tr><td>PRICE</td><td><xsl:value-of select="price" /></td></tr>
      <tr><td>SUBJECT</td><td><p><xsl:value-of select="subject"
      /></p></td></tr>
      </xsl:template>
      </xsl:stylesheet>
      --------------------------------------------------------

      BooksTransform_title.xsl
      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes" />
      <xsl:template match="/">
      <html>
      <link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
      <head>
      <!-- This sends the title and number of books to the Title bar. -->
      <title>My Library - which contains <xsl:value-of
      select="count(/data/item)" /> books</title>
      </head>
      <body>
      <table>
      <!-- The is the Sortation Option section. -->
      <tr><td align="left"> Books Sorted by Titles </td><td align="left">
      Sort By: </td><td><a href="My_Books_main.xml" > Subject </a></td><td>
      or </td><td><a href="My_Books_author.xml"> Author </a></td></tr>
      </table>
      <!-- This contains a for-each loop used to loop through the XML data,
      sort it by subject,
      and place each itiem in it own HTML formatted table -->
      <xsl:for-each select="data/item">
      <xsl:sort select="normalize-space(title)" />
      <table border="4" bordercolor="#888888" ><!-- border color to dark
      gray -->
      <xsl:apply-templates select="." /><!-- the dot stops it from
      reprinting the 1st item count times -->
      </table>
      </xsl:for-each>
      </body>
      </html>
      </xsl:template>

      <!-- This template displays the XML date in table rows and table data
      units. It also
      has a for-each loop that display one or more authors according to the
      book data being parsed. -->
      <xsl:template match="/data/item">
      <tr bgcolor="beige"><td>TITLE</td><td><xsl:value-of select="title"
      /></td></tr>
      <tr><td>EDITION</td><td><xsl:value-of select="edition" /></td></tr>
      <!-- for-each loop -->
      <xsl:for-each select="author">
      <tr><td>AUTHOR/s</td><td><xsl:value-of select="." /></td></tr>
      </xsl:for-each>
      <tr><td>PUBLISHER</td><td><xsl:value-of select="publisher" /></td></tr>
      <tr><td>ISBN</td><td><xsl:value-of select="isbn" /></td></tr>
      <tr><td>LCCN</td><td><xsl:value-of select="lccn" /></td></tr>
      <tr><td>PRICE</td><td><xsl:value-of select="price" /></td></tr>
      <tr><td>SUBJECT</td><td><p><xsl:value-of select="subject"
      /></p></td></tr>
      </xsl:template>
      </xsl:stylesheet>
      --------------------------------------------------

      my_bookstyle.css
      body { font-size: 10pt; font-family: Arial, Helvetica, sans-serif;}
      A:link { color: #000000; text-decoration: underline;}
      A:visited { color: #336699; text-decoration: underline;}
      A:hover { color: #CC9900; text-decoration: underline;}
      table {width: 60%; }
      --------------------------------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.