[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Pretty-print or replace problem
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 <? 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],'>'))"/> <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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|