xsltproc and multiple-line text

Discussion in 'XML' started by Arndt Jonasson, Apr 25, 2007.

  1. 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?
     
    Arndt Jonasson, Apr 25, 2007
    #1
    1. Advertising

  2. > ? 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.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Apr 25, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yzzzzz
    Replies:
    0
    Views:
    740
    yzzzzz
    Nov 12, 2003
  2. Brett

    xsltproc and Entities

    Brett, Feb 27, 2004, in forum: XML
    Replies:
    1
    Views:
    969
    Alain Ketterlin
    Mar 1, 2004
  3. Darel Finkbeiner

    xsltproc and DocBook

    Darel Finkbeiner, Mar 21, 2007, in forum: XML
    Replies:
    5
    Views:
    836
    Joseph Kesselman
    Mar 22, 2007
  4. Arndt Jonasson

    text() in XPath limited in xsltproc?

    Arndt Jonasson, Aug 8, 2007, in forum: XML
    Replies:
    1
    Views:
    1,710
    Pavel Lepin
    Aug 8, 2007
  5. Glen Millard
    Replies:
    10
    Views:
    1,579
    Peter Flynn
    Mar 12, 2012
Loading...

Share This Page