Subject: RE: Immediately preceding-sibling
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 20 Oct 2003 17:58:09 +0100
|
To test whether the immediately preceding element is a nospace element,
use
test="preceding-sibling::*[1][self::nospace]"
Michael Kay
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> m.vanrootseler@xxxxxxxxx
> Sent: 20 October 2003 16:00
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Immediately preceding-sibling
>
>
> 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):
>
> <root>
> <page id="1">
> <line id="1">
> <word id="1">One</word>
> <nospace/>
> <word id="2">Two</word>
> <word id="3">Three</word>
> <nospace/>
> <word id="4">Four</word>
> <word id="5">Five</word>
> </line>
> </page>
> </root>
>
> 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="/">
> <html>
> <head>
> </head>
> <body>
> <table border="0">
> <xsl:apply-templates select="root/page"/>
> </table>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template match="page">
> [page <xsl:value-of select="@id"/>]
> <br/>
> <br/>
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="line">
> <xsl:value-of select="@id"/>
> <xsl:text> </xsl:text>
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="word">
> -->???<--
> <xsl:apply-templates/>
> </xsl:template>
>
> Has anyone got any idea how to accomplish getting the XPath
> right? Much appreciated.
>
> Mick
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|