[xsl] Immediately preceding-sibling

Subject: [xsl] Immediately preceding-sibling
From: m.vanrootseler@xxxxxxxxx
Date: Mon, 20 Oct 2003 16:59:56 +0200
I have the following problem that I've been staring at for too long now.
I'm sure the solution is a simple one, I just can't find it. I have the
following XML (simplified):

	<page id="1">
		<line id="1">
			<word id="1">One</word>
			<word id="2">Two</word>
			<word id="3">Three</word>
			<word id="4">Four</word>
			<word id="5">Five</word>

What I want to do is to present the contents of the line; where a word
is *not* preceded by a <nospace/> tag, I want to put a space, where it
*is* preceded by a <nospace/> tag, I want to display an underscore. In
other words, I'm looking for a way to find the *immediate* preceding
<nospace/> tag to a <word>-tag. The result should look like this:

One_Two Three_Four Five

I can't get the XPath right by using preceding-sibling::nospace. I'm
using MSMXL and my XSLT looks like this (and I have to stick to the
nested templates):

<xsl:template match="/">
		<table border="0">
			<xsl:apply-templates select="root/page"/>
<xsl:template match="page">
	[page <xsl:value-of select="@id"/>]

<xsl:template match="line">
	<xsl:value-of select="@id"/>
	<xsl:text> </xsl:text>

<xsl:template match="word">

Has anyone got any idea how to accomplish getting the XPath right? Much


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread