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

Pretty-print or replace problem

Subject: Pretty-print or replace problem
From: Maik Stührenberg <Maik.Stuehrenberg@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Feb 2003 10:44:06 +0100
xsl pretty print
Hello,

I have a huge 'replace' related problem. I had a look to the archive and saw some global solutions but none of them did fit. The problem is this:
I have an XML document with some XML sourcecode, marked as <code>...</code>, declared in the DTD as #PCDATA. This code is transformed into XHTML, no problem at all. The next step I tried is to do some kind of 'pretty-print', eg. to format XML keywords like ELEMENT, ATTLIST and so on with colors different from the ones for the name of an element/attribution or its content model (using simply the XHTML span element). Two problems have arisen:
1. How do I match the &lt;?
2. (the bigger one) How do I manage to select the separate text content of the node? I tried it with the XSLT shown below, but there has to be another way.


Any help would be greatly appreciated. Kind regards,

Maik Stührenberg

<xsl:template match="Code">
<span style="font-family:monospace">
<xsl:call-template name="pretty"/>
</span>
</xsl:template>

<xsl:template name="pretty">
<xsl:variable name="lt" select="substring-before(text()[contains(.,'E')] | text()[contains(.,'A')],'!')"/>
<xsl:variable name="elem" select="substring-before(substring-after(.,'!'),' ')"/>
<xsl:variable name="name" select="substring-before(substring-after(text()[$elem],' '),'(')"/>
<xsl:variable name="content_model" select="substring-before(substring-after(text()[$name],'('),')')"/>
<xsl:variable name="gt" select="substring-after(text()[$content_model],substring-before(text()[$content_model],'&gt;'))"/>
<xsl:for-each select="text()[contains(.,$elem)]">
<span style="color:green"><xsl:value-of select="$lt"/></span>
<xsl:text>!</xsl:text>
<span style="color:red"><xsl:value-of select="$elem"/></span>
<xsl:text> </xsl:text>
<span style="color:black"><xsl:value-of select="$name"/></span>
<xsl:text>(</xsl:text>
<span style="color:blue"><xsl:value-of select="$content_model"/></span>
<xsl:text>)</xsl:text>
<span style="color:green"><xsl:value-of select="$gt"/></span>
</xsl:for-each>
</xsl:template>




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.