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

RE: replacing special characters in xsl:copy

Subject: RE: replacing special characters in xsl:copy
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 6 Jun 2007 18:02:07 +0100
RE:  replacing special characters in xsl:copy
The message element doesn't contain any "<" characters, so there are none to
replace. The string value of this element is " Text warning of foo".
Wrapping text in CDATA has no effect unless there are characters that would
otherwise be treated as markup, in which case it tells the XML parser to
treat such characters as if they had been escaped - for example "<" is
treated as a representation of the character "<" and not as markup. The
actual CDATA start and end markup is no more accessible to your stylesheet
than the quotes around an attribute value.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Dunning, John [mailto:jdunning@xxxxxxx] 
> Sent: 06 June 2007 17:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  replacing special characters in xsl:copy
> 
> Hello all,
> I'm just beginning to get into XSLT 2.0 and I'm trying to 
> copy the XML source to an HTML report; what I would like to 
> do is replace "<" and ">"
> in the copied source with "&lt;" and "&gt;".
> 
> The soure looks similar to:
> 
>   <task location="L:\\build-log.xml:48: " name="foo" time="0 seconds">
>     <message priority="warn"><![CDATA[ Text warning of foo 
> ]]></message>
>   </task>
> 
> What I've got so far is this:
> 
> <xsl:output method="html" indent="yes"/>
>   <xsl:template match="/">
>   <html>
>     <body>
> 	<xsl:for-each select="for $f in collection
> 	
> ('file:///c:/temp?select=*.xml;recurse=yes;on-error=ignore')  return  
>             saxon:discard-document($f)">
> 		<xsl:choose>     
> 		  <xsl:when test="//message[@priority='warn']">
> <h2>Warning in <xsl:value-of select="document-uri(.)"/>:</h2> <pre>
>    <xsl:copy-of
> select="replace(//message[@priority='warn'],'&lt;','&lt;')"/>
> </pre>			
> 		 </xsl:when>
>  		 <xsl:otherwise>
> <h2>No errors or warnings in <xsl:value-of 
> select="document-uri(.)"/></h2>
> 		 </xsl:otherwise>
>         </xsl:choose>
>    </xsl:for-each>
>     </body>
>   </html>
> </xsl:template>
> 
> 
> What my desired output would be is:
> 
> <h2>Warning in file:/c:/temp/foo.xml </h2> <pre>
>   &lt;task location="L:\\build-log.xml:48: " name="foo" 
> time="0 seconds"&gt;
>     &lt;message priority="warn">&lt;![CDATA[ Text warning of 
> foo ]]&gt;&lt;/message&gt;
>   &lt;/task&gt;
> </pre>
> 
> Is what I'm trying to do possible?  Am I on the right track?  
> Any suggestions gratefully received.
> 
> TIA,
> John

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.