Eliot Kimber
> I'm trying to create a document that contains the incoming XML exactly
> as it appears, with tags, attributes and everything.
> <fo:block>
> <xsl:copy-of
> select="/"/>
> </fo:block><
You can't just put the elements literally out into the FO--the FO
processor will have no idea what to do with them. You have to convert
the input elements to escaped text, which can do with something like this:
<fo:block linefeed-treatment="preserve"
white-space-treatment="preserve"
white-space-collapse="false"
>
<xsl:apply-templates select="/" mode="copy-markup"/>
</fo:block>
<xsl:template match="*" mode="copy-markup"
<xsl:text><</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:apply-templates select="@*" mode="copy-markup"/>
<xsl:text>></xsl:text>
<xsl:apply-templates mode="copy-markup"/>
<xsl:text><</xsl:text>
<xsl:value-of select="name(.)"/>
</xsl:text>></xsl:text>
</xsl:template>
<xsl:template match="@*" mode="copy-markup">
<xsl:text>
</xsl:text><!-- newline and indention for each attribute -->
<xsl:value-of select="concat(name(), '=')"/>
<xsl:text>"</xsl:text>
<xsl:value-of select="string(.)"/>
<xsl:text>"</xsl:value-of><!-- NOTE: doesn't handle quotes in
attribute values -->
</xsl:template>
<xsl:template match="text()" mode="copy-markup">
<xsl:value-of select="."/>
</xsl:template>
This should get you pretty close. This is for XSLT 1.0 and doesn't take
namespaces into account. A more complete, namespace-aware solution would
be easier to do with XSTL 2.0. I also didn't account for processing
instructions or comments, but you can probably figure that part out. |