This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Output XML doc with XSL doc name in comment


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?

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

</xsl:stylesheet>

--------------------------------------------------------
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'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

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

<!-- match elements -->
	<xsl:template match ="*" mode='toText'>
		<xsl:choose>
		<!-- elements containing stuff need an end tag, empty ones
don't -->
			<xsl:when test ="*|text()|comment()">
				<xsl:text>&lt;</xsl:text>
				<xsl:value-of select ="name()"/>
					<xsl:apply-templates
select='namespace' mode="toText"/>
					<xsl:apply-templates select='@*'
mode="toText"/>
				<xsl:text>&gt;</xsl:text>
				<xsl:apply-templates mode = "toText"/>
				<xsl:text>&lt;/</xsl:text>
					<xsl:value-of select ="name()"/>
				<xsl:text>&gt;</xsl:text>
		</xsl:when>
	<!-- do an empty element -->
		<xsl:otherwise>
			<xsl:text>&lt;</xsl:text>
			<xsl:value-of select ="name()"/>
			<xsl:apply-templates select='namespace'
mode="toText"/>
					<xsl:apply-templates select='@*'
mode="toText"/>
			<xsl:text>/&gt;</xsl:text>
		</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!-- 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>
	</xsl:template>

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

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

</xsl:stylesheet>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]