loading a single xml file with different stylesheets

Discussion in 'XML' started by jim, Jul 23, 2007.

  1. jim

    jim Guest

    Hi

    How can I load a different stylesheet depending on the html link I click
    to output the same xml file?

    I want to click on either the 'simple' or 'detailed' link and my xml
    file is output using a stylesheet designed for that link.

    At the moment I can only output one by linking to the stylesheet inside
    the xml file.

    Any ideas?




    ===============
    data_movies.xml
    ===============

    <?xml version="1.0"?>
    <?xml:stylesheet type = "text/xsl" href = "list_detailed.xsl"?>
    <data>
    <record timestamp="7/23/2007 1:47:17
    PM"><movie>trainspotting</movie><genre>drama</genre><rating>5</rating></record>
    <record timestamp="7/23/2007 1:47:17
    PM"><movie>unforgiven</movie><genre>western</genre><rating>4</rating></record>
    <record timestamp="7/23/2007 1:47:17
    PM"><movie>scarface</movie><genre>ganster</genre><rating>5</rating></record>
    <record timestamp="7/23/2007 1:47:17 PM"><movie>the godfather part
    I</movie><genre>ganster</genre><rating>5</rating></record>
    <record timestamp="7/23/2007 1:47:17 PM"><movie>the
    departed</movie><genre>action</genre><rating>4</rating></record>
    </data>




    =================
    list_detailed.xsl
    =================

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

    <html>

    <head>

    <link rel="stylesheet" type="text/css" href="mystyle.css" />

    <title>Results</title>

    </head>

    <body>

    <table>

    <col width="50%"/>
    <col width="40%"/>
    <col width="10%"/>

    <tr>
    <th class="head">Title</th>
    <th class="head">Genre</th>
    <th class="head">Rating</th>
    </tr>

    <xsl:for-each select="data/record">
    <xsl:sort select="movie"/>

    <tr>
    <td><xsl:value-of select="movie"/></td>
    <td><xsl:value-of select="genre"/></td>
    <td><xsl:value-of select="rating"/></td>
    </tr>

    </xsl:for-each>

    </table>

    <p class = "back"><a href = "index.html">Add Movie</a></p>

    </body>
    </html>


    </xsl:template>
    </xsl:stylesheet>




    ===============
    list_simple.xsl
    ===============

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

    <html>

    <head>

    <link rel="stylesheet" type="text/css" href="mystyle.css" />

    <title>Results</title>

    </head>

    <body>

    <table>

    <col width="100%"/>

    <tr>
    <th class="head">Title</th>
    </tr>

    <xsl:for-each select="data/record">
    <xsl:sort select="movie"/>

    <tr>
    <td><xsl:value-of select="movie"/></td>
    </tr>

    </xsl:for-each>

    </table>

    <p class = "back"><a href = "index.html">Add Movie</a></p>

    </body>
    </html>


    </xsl:template>
    </xsl:stylesheet>
     
    jim, Jul 23, 2007
    #1
    1. Advertising

  2. jim

    Wizfrog Guest

    It is fairly simple with an XSL transform in Javascript.

    Here is a very good example of what you can do, with multiple XSL
    stylesheets, or one stylesheet with multiple templates to use to
    transform the same XML document.


    http://www.perfectxml.com/articles/xml/XSLTInMSXML.asp?pg=2

    Good luck
     
    Wizfrog, Jul 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Dynamically loading stylesheets

    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Nov 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,406
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 24, 2004
  2. Andries
    Replies:
    5
    Views:
    4,499
    Sean Jorden
    Sep 9, 2003
  3. Replies:
    2
    Views:
    350
    bruce barker
    Mar 19, 2007
  4. Sachin
    Replies:
    1
    Views:
    392
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jun 1, 2007
  5. Erik Wasser
    Replies:
    5
    Views:
    528
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page