473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XSLT: all but the last child

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

Oct 28 '05 #1
2 1821


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/
Oct 28 '05 #2
Thanks Martin. I had assumed that it was a formatting problem in the
web page offering this solution :)

Oct 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
2
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
2
by: Bart | last post by:
I'm trying to transform an xml file to another xml file by using xslt. for every child node, i need to do some transformations, except for the first one, so I can't use a for-each construction....
5
by: Douglas Steen | last post by:
Here's what I have (in snippets) ** XML ** <parent> <child> <grandchild/> </child> </parent> ** XSLT ** <xsl:template match="/parent">
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
2
by: Sharkie | last post by:
I'm relatively new to XSLT, having strong background in bunch of other programming languages (Perl, Java, etc.). I'm writing an XSLT stylesheet, converting XML into HTML. Everything works just...
7
by: pstachy | last post by:
Hi all, I'm having problem with XSLT transformation concerned with sort and numberings at a time. I wish to have my registries sorted alfabetically and would like them to have numberings at a...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.