RE: [xsl] Output escaped characters that represent the CR as an attribute

Subject: RE: [xsl] Output escaped characters that represent the CR as an attribute
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 29 Sep 2004 21:00:29 +0100
The following stylesheet

<TagwithAttribute att1="XXXX&#x0D;&#x0A;YYYY"
xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>

when run against any source document, produces the output (from Saxon 8.1)

<?xml version="1.0" encoding="UTF-8"?>
<TagwithAttribute att1="XXXX&#xD;&#xA;YYYY"/> 

I can't imagine the leading zeroes are really essential to your application.

The XSLT serializer ought to escape any CR and NL characters in the
attribute value. The 1.0 spec specifically mentions this in the case of NL
characters. It isn't explicit about it in the case of CR, but it is implicit
in the general requirement that the serializer should produce a
representation that "round-trips": i.e. that regenerates the identical
result tree when parsed.

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


> -----Original Message-----
> From: good all [mailto:good2all@xxxxxxxxx] 
> Sent: 29 September 2004 19:42
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Output escaped characters that represent the 
> CR as an attribute
> 
> Hi, all,
> 
> I have a requirement to out the escaped characters that represent the
> CR as an attribute.What I want is:
> 
> <TagwithAttribute att1="XXXX&#x0D;&#x0A;YYYY"/>
> 
> Regards an old posts in this list, we can output these characters as:
> <xsl:text 
> disable-output-escaping="yes">XXXX&amp;#x0D;&amp;#x0A;YYYY</xsl:text>
> 
> However, this works fine to element only, doesn't work if I want to
> assgin this to an attribute.Please see the following files.
> 
> Any replys are highly appreciated.
> 
> thanks.
> Good2all
> 
> Source XML File:
> ------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="x0Dx0A_Test.xslt"?>
> <dummy/>
> 
> ------------------
> XSLT file:
> --------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:fo="http://www.w3.org/1999/XSL/Format";>
> <xsl:template match="/">
> <someTag>
> 	<xsl:text 
> disable-output-escaping="yes">XXXX&amp;#x0D;&amp;#x0A;YYYY</xsl:text>
> 	<tagwithattri>
> 		<xsl:attribute name="att1">
> 			<xsl:text 
> disable-output-escaping="yes">XXXX&amp;#x0D;&amp;#x0A;YYYY</xsl:text>
> 		</xsl:attribute>
> 	</tagwithattri>
> </someTag>
> </xsl:template>
> </xsl:stylesheet>
> 
> 
> --------------------
> Output XML File:
> ----------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <someTag 
> xmlns:fo="http://www.w3.org/1999/XSL/Format";>XXXX&#x0D;&#x0A;YYYY
> <tagwithattri att1="XXXX&amp;#x0D;&amp;#x0A;YYYY"/>
> </someTag>
> 
> ----------------------
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--

Current Thread