Copying elements and their attributes

Subject: Copying elements and their attributes
From: "Christopher A. Brooks" <webmaster@xxxxxxxxxx>
Date: Wed, 20 Sep 2000 22:25:36 -0600
Hi all,

    I want to create a little stylesheet to give me some syntax
highlighting.  The idea is to take an arbitrary XML peice wrapped in a "code
element" like:

<code type="xml">
    <foo type="fooed">
        <bar>test text</bar>
    </foo>
</code>

And have on the output something like:

&lt;foo type="fooed"&gt;
    &lt;bar&gt;test text&lt;/bar&gt;
&lt;/foo&gt;

With appropriate XSL inline-sequence modifiers added for colouring (it is
important to note that I don't think I want to use xsl:copy - correct me if
I'm wrong -- because I will need to be wrapping everything in XSL-fo
elements as well, to turn into PDFs and the like).

Using Michael Kay's excellent XSLT book, I managed to hack out:

<xsl:template match="@*|node()" mode="code">
    <fo:block text-align="start" line-height="1.5" font-family="Courier"
start-indent="20pt" end-indent="20pt" >
        <fo:inline-sequence color="silver">&lt;<xsl:value-of
select="name()"/>&gt;</fo:inline-sequence>
        <fo:inline-sequence color="#B00"><xsl:value-of
select="."/></fo:inline-sequence>
        <xsl:apply-templates mode="code"/>
        <fo:inline-sequence color="silver">&lt;/<xsl:value-of
select="name()"/>&gt;</fo:inline-sequence>
    </fo:block>
</xsl:template>

This produces ok output, but the line <fo:inline-sequence
color="#B00"><xsl:value-of select="."/></fo:inline-sequence> doesn't output
what I want (I want it to output "test text" in red, between bar tags, and
it does that, followed by another test text in black, and test text in red
between the foo tags).  Also, the attribute "type="fooed"" isn't outputted
at all (how do you match on an arbitrary attribute?).

Anyone have any suggestions on perhaps a better method of doing this, or
pointing out a few conceptual mistakes I have made, or even just a prod in
the right direction?

Thanks,

Chris
--
Christopher A. Brooks, NetRPG

Email: webmaster@xxxxxxxxxx
Web: http://www.netrpg.com/webmaster/


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


Current Thread