Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 23rd, 2006, 07:11 AM
Registered User
 
Join Date: Aug 2006
Location: Belo Horizonte, Minas Gerais, Brazil.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can i rewrite the example bookClient.htm

Hi iam from brazil, anda my english is not good...

try understand:

How can i rewrite the example bookClient.htm of book PROFESSIONAL XML (year 2000), using a more recent programming?

The example create a xml document and show this in a html document with xsl.
to manipulate the xml, the example use JavaScript.

I read in the internet that example is delayed

HERE THE EXAMPLE:

<html>
<head>
<title>Wrox Press book data entry page</title>
<body onload="initializeBook()" >
    <h1>Wrox Press book data entry page</h1>
    <h3>Book information:</h3>
    <table>
        <tr>
            <td>Title:</td>
                        <td><input id="txtTitle"></td>
        </tr>
        <tr>
            <td>Publisher:</td><td><input id="txtPublisher"></td>
        </tr>
        <tr>
            <td>Published Date:</td><td><input id="txtPubDate"></td>
        </tr>
        <tr>
            <td>Abstract:</td><td><input id="txtAbstract"></td>
        </tr>
        <tr>
            <td>Pages:</td><td><input id="txtPages"></td>
        </tr>
        <tr>
            <td>ISBN:</td><td><input id="txtISBN"></td>
        </tr>
        <tr>
            <td>Price:</td><td><input id="txtPrice"></td>
        </tr>
    </table>
    <input id="btnUpdate" type="button" value="Update book info" onclick="updateBookInfo()">
    <h3>Authors:</h3>
    <table>
        <tr>
            <td>Author:</td><td><input id="txtAuthor"></td>
        </tr>
    </table>
    <input id="btnAddAuthor" type="button" value="Add author" onclick="addAuthor()">

    <h3>Categories:</h3>
    <table>
        <tr>
            <td>Category:</td><td><input id="txtCategory"></td>
        </tr>
    </table>
    <input id="btnAddCategory" type="button" value="Add Category" onclick="addCategory()">
    <xml id="docBook">
        <book>
        </book>
    </xml>
    <script>
    var docBook;
    function initializeBook()
    {
        docBook = document.all("docBook").XMLDocument;
        docBook.async = "false";
        renderElements();
    }

    function createOrReplaceElement(sElementName, sElementValue, elementParent)
    {
        var elementItem;
        var textValue;
        var nodelistOldItem;

        elementItem = docBook.createElement(sElementName);
        textValue = docBook.createTextNode(sElementValue);
        elementItem.appendChild(textValue);

        nodelistOldItem = elementParent.getElementsByTagName(sElementName);
        if (nodelistOldItem.length > 0)
        {
            elementParent.replaceChild(elementItem, nodelistOldItem.item(0));
        }
        else
        {
            elementParent.appendChild(elementItem);
        }
    }
    function updateBookInfo()
    {
        createOrReplaceElement("Title", txtTitle.value, docBook.documentElement);
        createOrReplaceElement("Publisher", txtPublisher.value, docBook.documentElement);
        createOrReplaceElement("PubDate", txtPubDate.value, docBook.documentElement);
        createOrReplaceElement("Abstract", txtAbstract.value, docBook.documentElement);
        createOrReplaceElement("Pages", txtPages.value, docBook.documentElement);
        createOrReplaceElement("ISBN", txtISBN.value, docBook.documentElement);
        createOrReplaceElement("Price", txtPrice.value, docBook.documentElement);

        renderElements();
    }
    function addAuthor()
    {
        var elementAuthor;
        var textAuthor;
        var nodelistAuthors;
        var elementAuthors;
        elementAuthor = docBook.createElement("Author");
        textAuthor = docBook.createElement(txtAuthor.value);
        elementAuthor.appendChild(textAuthor);
        nodelistAuthors = docBook.getElementsByTagName("Authors");
        if (nodelistAuthors.length == 0)
        {
            elementAuthors = docBook.createElement("Authors");
            docBook.documentElement.appendChild(elementAuthors );
        }
        else
        {
            elementAuthors = nodelistAuthors.item(0);
        }
        elementAuthors.appendChild(elementAuthor);
        renderElements();
    }
    function addCategory()
    {
        var elementCategory;
        var textCategory;
        var nodelistRecSubjCategories;
        var elementRecSubjCategories;
        elementCategory = docBook.createElement("category");
        textCategory = docBook.createElement(txtCategory.value);
        elementCategory.appendChild(textCategory);
        nodelistRecSubjCategories = docBook.getElementsByTagName("RecSubjCategories");
        if (nodelistRecSubjCategories.length == 0)
        {
            elementRecSubjCategories = docBook.createElement("RecSubjCategories");
            docBook.documentElement.appendChild(elementRecSubj Categories);
        }
        else
        {
            elementRecSubjCategories = nodelistRecSubjCategories.item(0);
        }
        elementRecSubjCategories.appendChild(elementCatego ry);
        renderElements();
    }
    function renderElements()
    {
        document.all("divRawXML").innerText = docBook.xml;
        bookInfo.innerHTML = docBook.transformNode(bookXSL.documentElement);
        authorTable.innerHTML = docBook.transformNode(authorXSL.documentElement);
        categoryTable.innerHTML = docBook.transformNode(categoryXSL.documentElement) ;
    }
    </script>
   <xml id="bookXSL">
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:output method="html" version="1.0" indent="yes"/>
                <xsl:template match="/">
                      <xsl:choose>
                           <xsl:when test="/book/Title[. != '']">
                                <table border="0" cellpadding="1">
                                     <tr>
                                          <td>Title:</td>
                                          <td><xsl:value-of select="/book/Title"/></td>
                                      </tr>
                                     <tr>
                                          <td>Publisher:</td>
                                          <td><xsl:value-of select="/book/Publisher"/></td>
                                     </tr>
                                     <tr>
                                          <td>Published Date:</td>
                                          <td><xsl:value-of select="/book/PubDate"/></td>
                                     </tr>
                                     <tr>
                                          <td>Abstract:</td>
                                          <td><xsl:value-of select="/book/Abstract"/></td>
                                     </tr>
                                     <tr>
                                          <td>Pages:</td>
                                          <td><xsl:value-of select="/book/Pages"/></td>
                                     </tr>
                                     <tr>
                                          <td>ISBN:</td>
                                          <td><xsl:value-of select="/book/ISBN"/></td>
                                     </tr>
                                     <tr>
                                          <td>Price:</td>
                                          <td><xsl:value-of select="/book/Price"/></td>
                                     </tr>
                                </table>
                           </xsl:when>
                           <xsl:otherwise>
                                <p>Book Information not yet specified.</p>
                           </xsl:otherwise>
                      </xsl:choose>
                </xsl:template>
        </xsl:stylesheet>
    </xml>
    <xml id="authorXSL">
         <div xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <table border="0" cellpadding="1">
            <tr>
                <td><strong>Authors</strong></td>
            </tr>
            <tr>
                <td>You entered:</td>
            </tr>
            <xsl:for-each select="/Book/Authors/Author">
                <tr>
                    <td><xsl:value-of select="text()"/></td>
                </tr>
            </xsl:for-each>
        </table>
         </div>
    </xml>
    <xml id="categoryXSL">
         <div xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
           <table border="0" cellpadding="1">
            <tr>
                <td><strong>Categories</strong></td>
            </tr>
            <tr>
                <td>You entered:</td>
            </tr>
            <xsl:for-each select="/book/recSubjCategories/category">
                <tr>
                    <td><xsl:value-of select="text()"/></td>
                </tr>
            </xsl:for-each>
        </table>
         </div>
    </xml>

    <h2>Book information</h2>
    <p><div id="bookInfo"></div></p>
    <p><div id="authorTable"></div></p>
    <p><div id="categoryTable"></div></p>
    The text expression of the current contents of the DOM tree is:
    <pre><div id="divRawXML"></div></pre>
</body>
</head>
</html>


Keyne
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Rewrite kumiko Classic ASP Basics 1 April 17th, 2008 01:05 AM
rewrite problem twr195 Beginning PHP 1 March 11th, 2008 12:49 PM
isapi url rewrite question rykiel Classic ASP Professional 0 October 9th, 2007 03:22 AM
problem with URL rewrite mlcy ASP.NET 2.0 Professional 3 June 21st, 2007 06:05 PM
rewrite table by js gooly Javascript How-To 3 March 15th, 2004 04:34 AM



All times are GMT -4. The time now is 10:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.