xsl-list
[Top] [All Lists]

RE: Re: XSL in HTML

2003-11-18 21:26:11
Hi Erik,

Thank you very much for your reply and help.  I already know the way of
implementation which you sent me as an example.  I know that we can mention
the xsl in the xml file and the output will be in HTML when we open that
xml.  But my requirement is to have one HTML file and it should process the
xml with the xsl embedded in it and show the detail in that HTML.  I doubt
whether it is possible.  Please let me know if it is possible.

Regards,
R.Vishnu Varadhan.

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of
yguaba(_at_)yahoo(_dot_)com(_dot_)br
Sent: Tuesday, November 18, 2003 10:34 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Re: XSL in HTML


Hello Vishnu,

On 18 Nov 2003 at 8:47, Vishnu Vardan wrote:

Is it possible to embed xsl in a HTML like writing java script in HTML.

It is, but it won't accomplish anything. The XSL tags won't be
recognized by the browser and will be nothing more than dead weight
on your web page. Besides, if there are any text nodes (i.e. text
contained between opening and closing XSL tags), the text will be
visible when the HTML file is opened in a web browser, which is
probably not your intention.

What you can do, and which may be what you're looking for, is open an
XML file with an attached stylesheet in a web browser (as long as the
browser is recent, such as Netscape 7.1, Mozilla 1.5 or IE 6). The
XML will be processed on the fly according to the specified XSLT
stylesheet and you'll see the resulting HTML in the browser
(provided, of course, that the stylesheet is designed to output
HTML).

Try this:

(1) Save this simple XML code to a file named "text.xml":

-----------------

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<PAGE>
        <page_title>MY TEST PAGE</page_title>
        <page_content>This text is the body of my test page.</page_content>
</PAGE>

-----------------

(2) Now save this XSLT stylesheet to a file named "test.xsl":

-----------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<xsl:output method="html" indent="yes" encoding="iso-8859-1"/>
        <xsl:template match="/">
                <html>
                        <head>
                                <title>
                                        <xsl:apply-templates 
select="/PAGE/page_title"/>
                                </title>
                        </head>
                        <body>
                                <div style="color: Red; font-weight: bold;">
                                        <xsl:apply-templates 
select="/PAGE/page_content"/>
                                </div>
                        </body>
                </html>
        </xsl:template>
        <xsl:template match="PAGE/page_title">
                <xsl:value-of select="text()"/>
        </xsl:template>
        <xsl:template match="PAGE/page_content">
                <xsl:value-of select="text()"/>
        </xsl:template>
</xsl:stylesheet>

-----------------

Make sure both files are in the same directory (folder). Now open the
XML file in your browser. You should see the text contained in the
element "page_content" in red, bold type as a result of the
stylesheet transformation. If you don't attach an XSLT stylesheet to
the XML file with <?xml-stylesheet type="text/xsl" href="test.xsl"?>,
your XML code will be shown by the browser.

Hope this will give you some interesting ideas.

Good luck,

Erik

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>