Solved

Xml Transformation

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

730 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