RE: [xsl] Thinking Out loud - XML or XSL for boiler messages

Subject: RE: [xsl] Thinking Out loud - XML or XSL for boiler messages
From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxx>
Date: Sun, 29 Feb 2004 23:18:07 -0000

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Karl J. Stubsjoen
> Sent: 29 February 2004 21:45
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Thinking Out loud - XML or XSL for boiler messages
> 
> 
> Precisely what I was looking for...
> I've asked similar question before, but because the data I 
> was retrieving was wrapped within an attribute this sort of 
> template processing would not work.  At this point, I do not 
> have this trouble, the XML source is 100% my conception (the 
> other is an ADO XML recordset).

A more elegant way would be to have a separate xml file with lookup
values

xml file
<?xml version="1.0" ?>
<resource>
<para>Dr <firstname/>, Please read this letter</para>
</resource>	

Lookup xml file ( lookup.xml )
<?xml version="1.0" ?>
<resource>
<firstname>Jim</firstname>
</resource>	

xsl file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method = "html"/>
	<xsl:variable name="lookup-data"
select="document('lookup.xml')"/>
	<xsl:template match="resource">	
		<html>
			<title></title>
			<body>
			<xsl:apply-templates select="para"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="para">
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="*">
	<xsl:variable name="currentname" select="local-name()"/>
		<xsl:value-of
select="$lookup-data/resource/child::*[local-name()=$currentname]"/>
	</xsl:template>
</xsl:stylesheet>

This lets u generate a lookup file to refer to, without generating a
whole bunch of xsl:templates...though u could use this technique with
xsl:param. This assumes though that you have no useful markup embedded
in your text other then tokens to be replaced, though you could easily
handle this by either using a namespace on the elements and a general
matching template for those, for example html:* elements could be
embedded in text with a matching xsl:template to just process them
normally...up to you.

Once again there are other methods.

gl, Jim


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


Current Thread