Click to See Complete Forum and Search --> : Inline Transformations


TNO
06-13-2008, 10:51 AM
Surely its possible to have an XSLT stylesheet inline in an XHTML page? I can combine SVG and XHTML no problem, but I'm having issues with XSLT + XHTML, am I doing something wrong?

http://thenewobjective.com/index.xhtml

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>The New Objective</title>

<meta http-equiv="imagetoolbar" content="no" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="Author" content="Michael Haufe (-TNO-)" />

<meta name="copyright" content="Copyright 2008 The New Objective, All Rights Reserved" />
<meta name="date" content="2008-06-12T11:21:19" />
<meta name="verify-v1" content="R0feprjtTw0IH8Qy+mQGRT9usfLFO/v/PlRFzfGRbUg=" />

<link rel="shortcut icon" type="image/x-icon" href="http://thenewobjective.com/favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://thenewobjective.com/css/base.css" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://thenewobjective.com/rss.xml" />

<script type="text/javascript" src="http://thenewobjective.com/js/TNO.Browser.js"></script>

<script type="text/javascript"></script>
</head>
<body>
<div id="title">The New Objective</div>
<div id="content">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="rss" select="document('rss.xml')" />
<xsl:template match="/">

<xsl:for-each select="$rss//channel/item/">
<div class="glass">
<xsl:value-of select="title" />
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</div>
<div id="footer">

Copyright © 2008 The New Objective. All Rights Reserved | <a href="javascript:void(show('privacy.html','center'))">Privacy Policy</a> | <a href="javascript:void(show('contact.html','center'))">Contact</a>
</div>
</body>
</html>


http://thenewobjective.com/rss.xml

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The New Objective</title>
<description>{}</description>
<lastBuildDate>Wed, 27 Feb 2008 13:57:08 -0600</lastBuildDate>
<link>http://thenewobjective.com/</link>
<atom:link href="http://thenewobjective.com/rss.xml" rel="self" type="application/rss+xml" />
<image>
<url>http://thenewobjective.com/img/rss.jpg</url>
<title>The New Objective</title>
<link>http://thenewobjective.com/</link>
</image>

<item>
<title>Under Reconstruction</title>
<description>Under Reconstruction</description>
<pubDate>2008-05-21T04:57:43</pubDate>
<guid>http://thenewobjective.com/index.xhtml</guid>
<link>http://thenewobjective.com/index.xhtml</link>
</item>
<item>
<title>VBScript Expansion Component Complete!</title>
<description>The VBScript Compansion Component (WSC) is complete</description>
<pubDate>2008-05-21T04:57:43</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-05-21T04-57-43.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-05-21T04-57-43.html</link>
</item>
<item>
<title>Consolidated Scripting Framework for VBS</title>
<description>Consolidated Scripting Framework Component (WSC)</description>
<pubDate>2008-04-29T02:28:25</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-04-29T02-28-25.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-04-29T02-28-25.html</link>
</item>
<item>
<title>CSS: Horizontal Menu</title>
<description>100% pure CSS pull down menu</description>
<pubDate>2008-03-25T01:55:43</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-03-25T01-55-43.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-03-25T01-55-43.html</link>
</item>
<item>
<title>Revenge of The Poring</title>
<description>Testing the Canvas Object Model with a twist...</description>
<pubDate>2008-03-24T23:53:45</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-03-24T23-53-45.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-03-24T23-53-45.html</link>
</item>
<item>
<title>Using JS/VBS to open a CD/DVD drive</title>
<description>Using JS/VBS to open a CD/DVD drive</description>
<pubDate>2008-03-13T07:20:59</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-03-13T07-20-59.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-03-13T07-20-59.html</link>
</item>
<item>
<title>Well, the blog works</title>
<description>Or so it appears...</description>
<pubDate>2008-03-12T08:00:38</pubDate>
<guid>http://thenewobjective.com/main/Blog/2008-03-12T08-00-38.html</guid>
<link>http://thenewobjective.com/main/Blog/2008-03-12T08-00-38.html</link>
</item>
</channel>
</rss>

rpgfan3233
06-13-2008, 11:21 AM
AFAIK, you can't do that. The XSLT should be applied via <?xml-stylesheet?> as a file, or you might possibly assign an id to it, and do things that way:
<?xml version=1.0"?>
<?xml-stylesheet type="text/xsl" href="#xsl"?>
<!-- skipping some stuff including the DOCTYPE -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="xsl">
I'm not sure if that will work because honestly I've never even thought about doing something like that!

I'm sure you have your reasons for wanting to do this inline (e.g. you basically don't want to rewrite the entire file), but the xsl:template element is useful for targeting only certain files. Perhaps you can take advantage of that if the code above doesn't quite work.

Edit: FWIW, that invalidates your XHTML.