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? 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 < and > 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><</xsl:text> <xsl:value-of select ="name()"/> <xsl:apply-templates select='namespace' mode="toText"/> <xsl:apply-templates select='@*' mode="toText"/> <xsl:text>></xsl:text> <xsl:apply-templates mode = "toText"/> <xsl:text></</xsl:text> <xsl:value-of select ="name()"/> <xsl:text>></xsl:text> </xsl:when> <!-- do an empty element --> <xsl:otherwise> <xsl:text><</xsl:text> <xsl:value-of select ="name()"/> <xsl:apply-templates select='namespace' mode="toText"/> <xsl:apply-templates select='@*' mode="toText"/> <xsl:text>/></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><--</xsl:text> <xsl:value-of select='.'/> <xsl:text>--></xsl:text> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] following-sibling or grou, Matts Isuls | Thread | RE: [xsl] Output XML doc with XSL d, Michael Kay |
[xsl] following-sibling or grouping, Matts Isuls | Date | RE: [xsl] Output XML doc with XSL d, TSchutzerWeissmann |
Month |