Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: all but the last child

Thread Tools

XSLT: all but the last child

Martin Plantec
Posts: n/a

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:

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

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">
<xsl:for-each select="line">
<xsl:apply-templates />
<xsl:if test="position() < last()">
<br />

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,


Reply With Quote
Martin Honnen
Posts: n/a

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
Reply With Quote
Martin Plantec
Posts: n/a
Thanks Martin. I had assumed that it was a formatting problem in the
web page offering this solution

Reply With Quote

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
problem with child text node when constraining other child node types Bryan Ax XML 6 05-17-2006 09:08 PM
restrict the value of one child based on value from another child leon XML 0 09-27-2005 03:32 PM
EJB: How to delete child entries from a parent-child CMR one-to-many relationship? davout Java 0 04-18-2004 07:02 PM
[HELP] Why the child window reopen a new child window ? bhchng ASP .Net 0 01-13-2004 07:17 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM