Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Access only next sibling element with XSL

Thread Tools

Access only next sibling element with XSL

Michael K?nig
Posts: n/a

I've an XML-file structured like this


I'like to extract the personal data depending on the label which
stands in the sibling <td> before, the result should look like this:


I know what labels can appear ("Nombre:", "Apellido:","Posición:") but
I don't know if they appear within the <tr>-Element and in which
order, so I can't use [position()=2] etc.

How do I realize this using XSLT?

I tried

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlnssl="" >
<xslutput method="text" encoding="ISO-8859-1"/>
<xsl:template match="table">

<xsl:template match="td[text()='Nombre:']">
<xsl:value-of select="following-sibling::td" />

<xsl:template match="td[text()='Appellido:']">
<xsl:value-of select="following-sibling::td" />

<xsl:template match="td[text()='Posición:']">
<xsl:value-of select="following-sibling::td" />

But the problem I have is that 'following-sibling::td' accesses ALL
following-siblings and not only the next.
I could imagine a solution making use of something like


but I don't know how to implemt it in XSLT.

Any suggestion? Thanks in advance.

Reply With Quote
Richard Tobin
Posts: n/a
In article <(E-Mail Removed) >,
Michael K?nig <(E-Mail Removed)> wrote:

> <xsl:template match="td[text()='Nombre:']">
> <xsl:value-of select="following-sibling::td" />
> </xsl:template>

You probably want:

<xsl:value-of select="following-sibling::td[1]" />

which will give you the first following td sibling.

-- Richard
Reply With Quote
David Carlisle
Posts: n/a

> But the problem I have is that 'following-sibling::td' accesses ALL
> following-siblings and not only the next.

That is true but is not your problem as you are using this with
<xsl:value-of select="following-sibling::td" />
and value-of _always_ discards all but the first node in document order
and gives the string value of that first node only.

If you want to make it explicit (and legal in xslt2) you can go

<xsl:value-of select="following-sibling::td[1]" />

But this makes no difference in xslt1.

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
javascript evaluate function - next sibling jman Javascript 2 12-12-2008 12:45 PM
Newbie XSL Question: Comparing to preceding-sibling within for-each Red XML 2 05-09-2007 01:44 PM
how to find not the next sibling but the 2nd sibling or find sibling "a" OR sinbling "b" Python 11 01-23-2006 07:04 PM
XSLT how to find 2nd next sibling? XML 1 12-06-2005 12:57 PM
Select next sibling XPath? Philipp Lenssen XML 1 11-25-2003 02:26 PM