Solved

Xml Transformation

Posted on 2003-10-27
3
250 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now