Solved

Xml Transformation

Posted on 2003-10-27
3
254 Views
Last Modified: 2010-04-06
hi,
i want to transform the xml document to html using xsl stylesheets...
but i could not get the data from xml doc properly..
pls let me know wht to be added in my code...

here is my xml dox named myxml.xml...
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="my.xsl"?>
<catalog>
<item name="Wondernut chrome" finish="chrome" locking="yes" quantity="4">
<description>Add a touch of security and style  with these lugnuts</description>
<threadsizelist>
   <threadsize>3/8-24</threadsize>
   <threadsize>7/16-20</threadsize>
   <threadsize>10mm*1.25</threadsize>
   <threadsize>12mm*1.25</threadsize>
</threadsizelist>

<wheelcompatibilty>
    <make>Aardwheels</make>
    <make>Chromeover</make>      
</wheelcompatibilty>

<wheelcompatibilty>
    <make>ZooSpokes</make>
   
</wheelcompatibilty>

<carcompatibilty make="ABC motarworks" year="all"></carcompatibilty>
<carcompatibilty mKE="yOGEU" year="1987-1988"></carcompatibilty>

<Keywordlist>
   <keyword>lugnut</keyword>
   <keyword>lug nuts</keyword>
   <keyword>siler</keyword>
   <keyword>shiny</keyword>

</Keywordlist>
<price amount="20" currency="$US" tax="0%"></price>
<shipping cost="5" currency="$US" surcharges=""></shipping>

</item>
</catalog>

And my xsl stylesheet is...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">
<xsl:output method="xml"/>
<xsl:template match="/">

<html>
 <head><title>Lydia's Lugnuts</title></head>

<BODY>
 
 <Table border="1">
   <tr>
    <td valign="top">
           <p>Lydia's Lugnuts current offerings:</p>
      <A href="locking.html">MoreLocking Nuts</A><BR/>
      <A href="exotic.html"> exotic Nuts</A><BR/>
      <A href="basic.html">Basic Nuts</A><BR/>
   </td>

   <td>
      <xsl:for-each select="">
            <p><xsl:value-of select="."/></p>
      </xsl:for-each>
   </td>
  </tr>
</Table>


Copywright Lydia's Lugnuts

</BODY>
</html>
</xsl:template>
</xsl:stylesheet>...


pls help me how to transform the xml doc into html...
Thanks in Advance
Archana
0
Comment
Question by:archanamanju
3 Comments
 
LVL 2

Accepted Solution

by:
ericsDev earned 25 total points
ID: 9669225
try this XSL, works here with the XML you posted:

XSL : play3.xsl
----------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="catalog">
            <html>
                  <head>
                        <title>Lydia's Lugnuts</title>
                  </head>
                  <BODY>
                        <Table border="1">
                              <tr>
                                    <td valign="top">
                                          <p>Lydia's Lugnuts current offerings:</p>
                                          <A href="locking.html">MoreLocking Nuts</A>
                                          <BR/>
                                          <A href="exotic.html"> exotic Nuts</A>
                                          <BR/>
                                          <A href="basic.html">Basic Nuts</A>
                                          <BR/>
                                    </td>
                                    <td>
                                          <xsl:for-each select="item">
                              Name: <xsl:value-of select="@name"/>
                                                <br/>
                              Finish: <xsl:value-of select="@finish"/>
                                                <br/>
                              Locking: <xsl:value-of select="@locking"/>
                                                <br/>
                              Quantity: <xsl:value-of select="@quantity"/>
                                                <br/>
                              -----------------------------<br/>
                              Price Info:<br/>
                              Price: <xsl:value-of select="price/@amount"/>
                                                <br/>
                              Currency: <xsl:value-of select="price/@currency"/>
                                                <br/>
                              Tax: <xsl:value-of select="price/@tax"/>
                                                <br/>
                              -----------------------------<br/>
                              Shipping  Info:<br/>
                              Cost: <xsl:value-of select="shipping/@cost"/>
                                                <br/>
                              Currency: <xsl:value-of select="shipping/@currency"/>
                                                <br/>
                              Surcharges: <xsl:value-of select="shipping/@surcharges"/>
                                                <br/>
                              -----------------------------<br/>
                              Description:<br/>
                                                <xsl:value-of select="description"/>
                                                <br/>
                              -----------------------------<br/>
                              Thread Sizes:<br/>
                                                <xsl:for-each select="threadsizelist/threadsize">
                                                      <xsl:value-of select="."/>
                                                      <br/>
                                                </xsl:for-each>
                              -----------------------------<br/>
                              Wheel Compatibility:<br/>
                                                <xsl:for-each select="wheelcompatibilty">
                                                      <xsl:for-each select="make">
                                          Make: <xsl:value-of select="."/>
                                                            <br/>
                                                      </xsl:for-each>
                                                </xsl:for-each>
                              -----------------------------<br/>
                              Car Compatibility:<br/>
                                                <xsl:for-each select="carcompatibilty">
                                    Make: <xsl:value-of select="@make"/>
                                                      <br/>
                                    Year: <xsl:value-of select="@year"/>
                                                      <br/>
                                                </xsl:for-each>
                              -----------------------------<br/>
                              Keyword List:<br/>
                                                <xsl:for-each select="Keywordlist/keyword">
                                                      <xsl:value-of select="."/>
                                                      <br/>
                                                </xsl:for-each>
                                          </xsl:for-each>
                                    </td>
                              </tr>
                        </Table>
                  </BODY>
            </html>
      </xsl:template>
</xsl:stylesheet>
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Xsl Nested Loop 4 30
Hide or Show Images using checkbox array in mysql database 11 280
Owl Carousel 6 235
Swiper slider stops between pages 11 51
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question