[xsl] Re: XSL in HTML

Subject: [xsl] Re: XSL in HTML
From: yguaba@xxxxxxxxxxxx
Date: Tue, 18 Nov 2003 15:03:34 -0200
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


Current Thread