XSLT: all but the last child

M

Martin Plantec

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
 
M

Martin Honnen

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()">
 
M

Martin Plantec

Thanks Martin. I had assumed that it was a formatting problem in the
web page offering this solution :)
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top