xsltproc and multiple-line text

A

Arndt Jonasson

I have this xslt transform ex.xsl and an instance document ex.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="text"/>

<xsl:template match="//*[contains(.,'fo') and string-length(.) > 3
and string-length(.) &lt; 15]">
node=<xsl:value-of select="local-name()"/>
match=(<xsl:value-of select="."/>)
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
</xsl:template>

</xsl:stylesheet>





<top>
<x>fo
o</x>
<y>bar</y>
</top>



When I run the command
$ xsltproc ex.xsl ex.xml

I get the following output:

node=top
match=(
fo
o
bar
)


node=x
match=(fo
o)
fo
o


That ought to be expected. What I cannot understand is that if I
change the tests that narrow down the length of the text, either
changing 3 to 4, or 15 to 14, nothing matches. What is the expected
length? Is it 4? What I originally tried to do was to find a call to
contains(., xxx) that would include the line break, and match, but I
failed to do that, and found this anomaly instead, which leads me to
suspect that the behaviour of xsltproc for string with line breaks in
them is not quite reliable.

Should I be able to match the text of the x element with the
expression

match="//*[contains(.,'fo
o') ]"

? Is there some other way to include a newline in the expression?
 
J

Joseph Kesselman

? Is there some other way to include a newline in the expression?

XML standardizes newline as the LF character, so you could represent it
as a numeric character reference (&10; or
).
> Should I be able to match the text of the x element with the
> expression
> match="//*[contains(.,'fo
> o') ]"

NO. Literal line breaks are treated differently in attribute values than
in element content; see
http://www.w3.org/TR/2006/REC-xml11-20060816/#AVNormalize
Use the numeric character reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top