[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Carriage returns in attribute values (poss libxslt bug)?


Subject: Re: [xsl] Carriage returns in attribute values (poss libxslt bug)?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Apr 2004 07:37:24 +0200

At 2004-04-20 19:19 -0700, Ramon M. Felciano @ Yahoo wrote:
Are there any special rules around XSLT processing of string values from attributes vs text() nodes?

In XSLT no, but there are in XML and since XSLT is an XML application you see it happening in XSLT.


I've noticed the libxslt seems to strip out carriage returns.

XML 1.0 Section 3.3.3 talks about attribute value normalization. The XML processor in libxslt is doing what it is supposed to be doing.


CRs are probably pretty rare in attribute values, but MSXML seems to handle them ok

Then I guess MSXML isn't handling them properly.


so I'm wondering if there any special rules I don't know about. I took a quick look through the XSLT spec and didn't seen anything.

XSLT assumes it is working with a conforming XML processor.


Here's how to reproduce it. Given this XML:
...
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="U:\Active Workspace\Development\IKRS\CentralClassifier\libxslt-bug.xslt"?>
<libxml>
<foo a="alpha
beta
delta"/>
</libxml>


and this stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="foo">
<attribute><xsl:value-of select="@a"></xsl:value-of></attribute>
</xsl:template>
</xsl:stylesheet>


MSXML produces:

<?xml version="1.0" encoding="UTF-8"?>
<attribute>alpha
beta
delta</attribute>

I wouldn't expect that from what is prescribed in XML 1.0.


whereas libxslt produces:

<?xml version="1.0" encoding="UTF-8"?>

<attribute>alpha beta delta</attribute>

Looks fine to me.


BTW, if you want your attribute to have a carriage return, you can use an entity to express the carriage return, then it doesn't get normalized.

I hope this helps.

.......................... Ken

--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Each week:   Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Hong Kong May 17-21; Bremen Germany May 24-28; Helsinki June 14-18

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


Current Thread
Keywords