DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: please help me in XSLT

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    please help me in XSLT

    Hi everyone,

    I have a XML file and an XSL file. Now, I want to generate an HTML file from these two files. I tried many times but it seems that NetBeans cannot read the data in XML file. It is killing me right now. Please help me. Thanks a lot.

    My XML file

    HTML Code:
    <ns0:My_BookShelf xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:ns1='http://xml.netbeans.org/schema/Book_Author'
    xmlns:ns0='http://xml.netbeans.org/schema/BookShelf'
    xsi:schemaLocation='http://xml.netbeans.org/schema/BookShelf BookShelf.xsd'>
    <ns0:Book_Extension ISBN_No="1-55860-819-2">
    <ns0:Book_Title>Information Visualization Perception for Design</ns0:Book_Title>
    <ns0:Author>
    <ns1:Author>Colin Ware</ns1:Author>
    </ns0:Author>
    <ns0:Publisher>Morgan Kaufmann</ns0:Publisher>
    <ns0:Edition>Edition 2, 2004</ns0:Edition>
    <ns0:Language>English</ns0:Language>
    <ns0:Number_Of_Pages>488</ns0:Number_Of_Pages>
    <ns0:Category>Scientific Book</ns0:Category>
    <ns0:Rating>4 Stars</ns0:Rating>
    <ns0:Additional_Material>Nothing</ns0:Additional_Material>
    <ns0:Cover_Type>Soft Cover</ns0:Cover_Type>
    <ns0:Ownership>Mine</ns0:Ownership>
    <ns0:Price>40.0</ns0:Price>
    <ns0escription>Good</ns0escription>
    </ns0:Book_Extension> 
    </ns0:My_BookShelf>
    My XSL file

    HTML Code:
    <html
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xslns="http://xml.netbeans.org/schema/BookShelf">
    <head>
    <title>My_BookShelf.xsl</title>
    </head>
    <body>
    <h2>My Bookshelf</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
    <th>ISBN No</th>
    <th>Book Title</th>
    
    <th>Publisher</th>
    <th>Edition</th>
    <th>Language</th>
    <th>Number of Pages</th>
    <th>Category</th>
    <th>Rating</th>
    <th>Additional Material</th>
    <th>Cover Type</th>
    <th>Price</th>
    <th>Ownership</th>
    <th>Description</th>
    </tr>
    <xsl:for-each select="My_BookShelf/Book_Extension">
    <tr>
    <td><xsl:value-of select="Category"/></td>
    <td><xsl:value-of select="Book_Title"/></td> 
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    My code in XSL file is to create a table with the rows (the records in XML file) and the columns (XML elements). However, it justs display the table in html file with no data. Please help me. Thank you.

  2. #2
    Join Date
    May 2009
    Posts
    60
    no use for-each
    xml is not a programming language

    to select you must use the namespace
    then exclude the namespace for the html code
    for css use style tag
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://xml.netbeans.org/schema/BookShelf"  xmlns:ns1="http://xml.netbeans.org/schema/Book_Author"
    exclude-result-prefixes="ns0 ns1">
    	<xsl:output method="html" indent="yes"/>
    	<xsl:template match="/">
    		<html xslns="http://xml.netbeans.org/schema/BookShelf">
    			<style type="text/css">
    			table{
    			border :1px black solid;
    			}
    			td,th{
        		border :1px black solid;
    			}
    			th{
    			background-color:#9acd32;
    			}
    			</style>
    			<body>
    				<xsl:apply-templates select="ns0:My_BookShelf"/>
    			</body>
    		</html>
    	</xsl:template>
    
    
    
    	<xsl:template match="ns0:My_BookShelf">
    		<table>
    			<tr>
    				<th>ISBN No</th>
    				<th>Book Title</th>
    
    				<th>Publisher</th>
    				<th>Edition</th>
    				<th>Language</th>
    				<th>Number of Pages</th>
    				<th>Category</th>
    				<th>Rating</th>
    				<th>Additional Material</th>
    				<th>Cover Type</th>
    				<th>Price</th>
    				<th>Ownership</th>
    				<th>Description</th>
    				<th>Author</th>
    			</tr>
    			<xsl:apply-templates select="ns0:Book_Extension"/>
    		</table>
    	</xsl:template>
    
    	<xsl:template match="ns0:Book_Extension">
    		<tr>
    			<td>
    				<xsl:value-of select="@ISBN_No"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Book_Title"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Publisher"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Edition"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Language"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Number_Of_Pages"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Category"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Rating"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Additional_Material"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Cover_Type"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Price"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Ownership"/>
    			</td>
    			<td>
    				<xsl:value-of select="ns0:Description"/>
    			</td>
    			<td><xsl:value-of select="ns0:Author/ns1:Author"/>
    			</td>
    		</tr>
    	</xsl:template>
    </xsl:stylesheet>
    result
    Code:
    <html xslns="http://xml.netbeans.org/schema/BookShelf">
      <style type="text/css">
    			table{
    			border :1px black solid;
    			}
    			td,th{
        		border :1px black solid;
    			}
    			th{
    			background-color:#9acd32;
    			}
    			
      </style>
      <body>
        <table>
          <tr>
            <th>ISBN No</th>
            <th>Book Title</th>
            <th>Publisher</th>
            <th>Edition</th>
            <th>Language</th>
            <th>Number of Pages</th>
            <th>Category</th>
            <th>Rating</th>
            <th>Additional Material</th>
            <th>Cover Type</th>
            <th>Price</th>
            <th>Ownership</th>
            <th>Description</th>
            <th>Author</th>
          </tr>
          <tr>
            <td>1-55860-819-2</td>
            <td>Information Visualization Perception for Design</td>
            <td>Morgan Kaufmann</td>
            <td>Edition 2, 2004</td>
            <td>English</td>
            <td>488</td>
            <td>Scientific Book</td>
            <td>4 Stars</td>
            <td>Nothing</td>
            <td>Soft Cover</td>
            <td>40.0</td>
            <td>Mine</td>
            <td>Good</td>
            <td>Colin Ware</td>
          </tr>
        </table>
      </body>
    </html>
    for learning i show the namespace ns1 by author
    Last edited by xml-looser; 02-13-2011 at 02:04 PM.

  3. #3
    Join Date
    Feb 2011
    Posts
    2

    Smile

    Oh yeah. It works properly. You are my life saver. I have spent two days on that stuff. Thank you so much.

Similar Threads

  1. Problem applying simple XSLT to XML
    By gregclark in forum XML
    Replies: 3
    Last Post: 08-26-2005, 05:07 AM
  2. Replies: 2
    Last Post: 05-04-2002, 02:50 AM
  3. Importing xslt into 1 master xslt then to html
    By Patrick Long in forum XML
    Replies: 1
    Last Post: 03-01-2002, 03:47 PM
  4. Replies: 0
    Last Post: 06-21-2001, 05:33 PM
  5. Multiple stylesheets with XSLT
    By Mark in forum XML
    Replies: 0
    Last Post: 04-10-2001, 05:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center