[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: RE: [xsl] Output XML doc with XSL doc name in comment
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 8 May 2002 13:21:12 +0100

With Saxon 7.1 you can do:

<xsl:comment>
  <xsl:value-of select="saxon:serialize(document(''))"/>
</xsl:comment>

Probably of academic interest but I thought I'd let you know!

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> TSchutzerWeissmann@xxxxxxxxxxxxxxxx
> Sent: 08 May 2002 11:27
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] 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
> 

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



Current Thread
Keywords