By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

xsltproc and multiple-line text

P: n/a
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:output 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?

Apr 25 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
? 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 &#xA;).
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-...6/#AVNormalize
Use the numeric character reference.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.