XSLT: all but the last child

Discussion in 'XML' started by Martin Plantec, Oct 28, 2005.

  1. Hello,

    I have done research to solve one of my problems, but the solution I
    found fails with an error message. Here is the (simple, beginner level)
    problem. My XML is:

    <para>
    <line>This is the first line.</line>
    <line>This is the second line.</line>
    <line>This is the third line.</line>
    </para>

    I would like to get the obvious XHTML for that, namely:

    <p>This is the first line.<br />
    This is the second line.<br />
    This is the third line.</p>

    In other words, I don't want a <br /> at the end if it's the last line.
    Here is the solution I have assembled based on my research:

    <xsl:template match="para">
    <p>
    <xsl:for-each select="line">
    <xsl:apply-templates />
    <xsl:if test="position() < last()">
    <br />
    </xsl:if>
    </xsl:for-each>
    </p>
    </xsl:template>

    I am doing server-side transformation with PHP using Sabltron as
    back-end. Error message is :

    Warning: Sablotron error on line 45: XML parser error 4: not
    well-formed (invalid token) in C:\path...\page.php on line 25
    FAILURE : XML parser error 4: not well-formed (invalid token) ; error
    code is 2

    What am I doing wrong?

    Thank you,

    Martin
     
    Martin Plantec, Oct 28, 2005
    #1
    1. Advertising

  2. Martin Plantec wrote:


    > <xsl:if test="position() < last()">


    XSLT is XML so you need to escape the '<' symbol as
    <xsl:if test="position() &lt; last()">


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 28, 2005
    #2
    1. Advertising

  3. Thanks Martin. I had assumed that it was a formatting problem in the
    web page offering this solution :)
     
    Martin Plantec, Oct 28, 2005
    #3
    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. Gerald Aichholzer
    Replies:
    2
    Views:
    2,621
    Gerald Aichholzer
    Jun 27, 2006
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,204
    David Schwartz
    Dec 9, 2003
  3. sangram
    Replies:
    16
    Views:
    2,086
  4. Johny
    Replies:
    8
    Views:
    416
  5. Wizfrog
    Replies:
    5
    Views:
    2,347
    Joe Kesselman
    Jul 14, 2007
Loading...

Share This Page