RE: [xsl] Output XML doc with XSL doc name in comment

Subject: RE: [xsl] Output XML doc with XSL doc name in comment
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Wed, 8 May 2002 11:26:34 +0100
Mike Ferrando wrote:

Dear Friends,
I am attempting to output the xsl document in a comment field when I
generate the new xml document.

I am not getting anywhere.

Anyone have a suggestion?

Mike F.
<xsl:template match="/">
    <xsl:variable name="rr" select="document('')"/>
    <xsl:value-of select="concat('xyz', $rr)"/>
   <xsl:apply-templates select="//*"/>


Hello Mike,

xsl:value-of will give you the text nodes in your xsl - that's unlikely to
be very much. To copy of the whole lot, one would use <xsl:copy-of
select="document('')"/>, but inside a comment this does even less. So it
looks like you can only put text inside comments.

In that case you will need something that turns xml into text. You could do
this with templates, I've included an example below.

There's no template for processing instructions, and I can't work out how to
include the namespace declarations, which is a problem, as is the fact that
the &lt; and &gt; in the stylesheet come out as < and >. 

Hope this is some use, 
Tom Weissmann

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>

<xsl:stylesheet version='1.0'

<xsl:template match='/'>
		<xsl:apply-templates select ="document('')/*" mode

<!-- match elements -->
	<xsl:template match ="*" mode='toText'>
		<!-- elements containing stuff need an end tag, empty ones
don't -->
			<xsl:when test ="*|text()|comment()">
				<xsl:value-of select ="name()"/>
select='namespace' mode="toText"/>
					<xsl:apply-templates select='@*'
				<xsl:apply-templates mode = "toText"/>
					<xsl:value-of select ="name()"/>
	<!-- do an empty element -->
			<xsl:value-of select ="name()"/>
			<xsl:apply-templates select='namespace'
					<xsl:apply-templates select='@*'
	<!-- match attributes -->
	<xsl:template match='@*' mode='toText'>
		<xsl:text> </xsl:text>
			<xsl:value-of select='name()'/>
		<xsl:text>="</xsl:text><xsl:value-of select ="."/>
		<xsl:text>" </xsl:text>

	<!-- match text -->
	<xsl:template match='text()' mode='toText'>
			<xsl:value-of select='.'/>

	<!-- match comments -->
	<xsl:template match ="comment()" mode ="toText">
		<xsl:value-of select='.'/>


 XSL-List info and archive:

Current Thread