Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xsltproc and multiple-line text

Reply
Thread Tools

xsltproc and multiple-line text

 
 
Arndt Jonasson
Guest
Posts: n/a
 
      04-25-2007
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput 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?

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      04-25-2007
> ? 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsltproc question - I am clueless and a newbie, so don't be too roughon me! Glen Millard XML 10 03-12-2012 09:41 PM
text() in XPath limited in xsltproc? Arndt Jonasson XML 1 08-08-2007 09:12 AM
xsltproc and DocBook Darel Finkbeiner XML 5 03-22-2007 02:09 PM
xsltproc and Entities Brett XML 1 03-01-2004 07:57 AM
[xsltproc] Empty elements in output document yzzzzz XML 0 11-12-2003 10:38 PM



Advertisments