RE: [xsl] generating dynamic XSL to apply to a single XML document

Subject: RE: [xsl] generating dynamic XSL to apply to a single XML document
From: "Steven Bethard" <bediviere@xxxxxxxxxxx>
Date: Wed, 10 Sep 2003 10:04:11 -0600
Ok, so I discovered that I should be able to avoid the temporary
stylesheet by embedding my stylesheet in my XML.  Unfortunately, I can't
seem to get this to work with the data import.  Here's my example:

---- data.xml ----
<?xml version="1.0" encoding="UTF-8"?>
<foo>
	<bar>
		<baz>aaa</baz>
	</bar>
	<bar>
		<baz>bbb</baz>
	</bar>
</foo>

---- formatted-data.xml ----
<?xml version="1.0"?>
<!DOCTYPE page [
<!ENTITY data SYSTEM "data.xml">
]>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<doc>
	<head>
		<xsl:stylesheet version="1.0"
		                id="stylesheet"
	
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
			<xsl:template match="xsl:stylesheet" />
			
			<xsl:template match="foo">
				<html><body>
				<xsl:apply-templates />
				</body></html>
			</xsl:template>

			<xsl:template match="baz">
				<h1>BAZ <xsl:value-of select="." /></h1>
			</xsl:template>

		</xsl:stylesheet>
	</head>
	<body>
		&data;
	</body>
</doc>

The file data.xml is the original data file that I need to format in
several ways.  The file formatted-data.xml would be generated
dynamically by the CGI script.  When I display this in Internet
Explorer, I get a single big heading with "BAZ", and the text "aaa bbb"
below it.  I can't guess why the "baz" template would only match one
thing, or why when it matches that one thing there is no content in the
"." node.

Can anyone tell me why this doesn't work?  (And hopefully how to make it
work...) :)

Steve


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Steven
Bethard
Sent: Wednesday, September 10, 2003 2:00 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] generating dynamic XSL to apply to a single XML document

I have a single XML document that contains the data.  There are several
different views of this data that I need to display, and exactly what
goes into a view will be determined by some selections in an HTML form.
So my plan had been to incorporate a CGI script that would take the form
parameters, generate the appropriate XSL stylesheet, and format the XML
document using this stylesheet.

The only way I know to apply a different XSL stylesheet to the same XML
document is something like:
<?xml version="1.0"?>
<!DOCTYPE page [
<!ENTITY data SYSTEM "data.xml">
]>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<page>
&data;
</page>
which (I believe) would mean I would have to save a file called
"style.xsl", and then have the CGI script return the above as xml data.

I'd rather not create a bunch of temporary files (for the "style.xsl"
files) if I can avoid it. Is there a better way to do this?

Steve


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


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


Current Thread