You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Kenneth Stephen <ma...@gmail.com> on 2005/08/10 23:31:38 UTC
Problems handling end-of-line character
Hi,
I'm having trouble processing the end of line character ( )
with XSLT. Here is my testcase :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY EOL "
">
<!ENTITY TAB "	">
<!ENTITY SPACE " ">
]>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl-common="http://exslt.org/common"
xmlns:exsl-str="http://exslt.org/strings"
version="1.0"
extension-element-prefixes="exsl-common exsl-str"
exclude-result-prefixes="exsl-common exsl-str">
<xsl:variable name="var1" xml:space="preserve">
<a>
x<!-- The content of "a" is &EOL;x&EOL -->
</a>
</xsl:variable>
<xsl:variable name="var2" xml:space="preserve">
<a>
x <!-- The content of "a" is &EOL;x&SPACE;&EOL -->
</a>
</xsl:variable>
<xsl:template match="/">
<xsl:if test="contains(exsl-common:node-set($var1)/a/text(),'&EOL;')">
<xsl:message>Contains EOL(1)</xsl:message>
</xsl:if>
<xsl:if test="contains(exsl-common:node-set($var2)/a/text(),'&EOL;')">
<xsl:message>Contains EOL(2)</xsl:message>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Xalan 2.6.3 (actually its the Xalan bundled with Rational Software
Architect, which is XML4J) produces the following.
file:///D:/xsl/code/testcases/Entities.xsl; Line #32; Column #17;
Contains EOL(2)
<?xml version="1.0" encoding="UTF-8"?>
I get similar results with Saxon 6.5.4 - which indicates that this
is probably not a Xalan bug. But in that case, I'm mystified as to why
the EOL chars in $var1 are invisible. Any ideas?
Thanks,
Kenneth
Re: Problems handling end-of-line character
Posted by da...@us.ibm.com.
> I'm having trouble processing the end of line character ( )
> with XSLT. Here is my testcase :
U+0020 is not the end-of-line character.
> <xsl:template match="/">
> <xsl:if
test="contains(exsl-common:node-set($var1)/a/text(),'&EOL;')">
> <xsl:message>Contains
EOL(1)</xsl:message>
> </xsl:if>
> <xsl:if
test="contains(exsl-common:node-set($var2)/a/text(),'&EOL;')">
> <xsl:message>Contains
EOL(2)</xsl:message>
> </xsl:if>
> </xsl:template>
This is because of attribute value normalization:
http://www.w3.org/TR/2004/REC-xml11-20040204/#AVNormalize
The second parameter to the contains() function is being normalized from
U+000A to U+0020, so by the time the XSLT processor sees the test
attribute, it sees a string with a single space character as the second
parameter.
Try the following template instead of yours:
<xsl:template match="/">
<xsl:if
test="contains(exsl-common:node-set($var1)/a/text(),'&EOL;')">
<xsl:message>Contains
EOL(1)</xsl:message>
</xsl:if>
<xsl:if
test="contains(exsl-common:node-set($var2)/a/text(),'&EOL;')">
<xsl:message>Contains
EOL(2)</xsl:message>
</xsl:if>
<xsl:if
test="contains(exsl-common:node-set($var1)/a/text(),'
')">
<xsl:message>Contains
EOL(3)</xsl:message>
</xsl:if>
<xsl:if
test="contains(exsl-common:node-set($var2)/a/text(),'
')">
<xsl:message>Contains
EOL(4)</xsl:message>
</xsl:if>
</xsl:template>
which results in the following output:
file:///V:/test/Stephen/test1.xsl; Line #32; Column #23; Contains EOL(2)
file:///V:/test/Stephen/test1.xsl; Line #35; Column #23; Contains EOL(3)
file:///V:/test/Stephen/test1.xsl; Line #38; Column #23; Contains EOL(4)
<?xml version="1.0" encoding="UTF-8"?>
I think you are either confused about attribute value normalization, or
how entities work.
Dave