[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
elements and their colors
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.