473,503 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access only next sibling element with XSL

Hello,

I've an XML-file structured like this

<table>
<tr>
<td>Nombre:</td>
<td>Joseph</td>
<td>Apellido:</td>
<td>Ratzinger</td>
<td>Posición:</td>
<td>Pope</td>
</tr>
</table>

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

<person>
<name>Joseph</name>
<surname>Ratzinger</surname>
<profession>Pope</profession>
</person>
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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" encoding="ISO-8859-1"/>
<xsl:template match="table">
<person>
<name><xsl:apply-templates
select="td[text()='Nombre:']"/></name>
<surname><xsl:apply-templates
select="td[text()='Appellido:']"/></surname>
<profession><xsl:apply-templates
select="td[text()='Posición:']"/></profession>
</person>
</xsl:template>

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

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

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

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

[position()=td[text()='Nombre:']position()+1]

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

Any suggestion? Thanks in advance.
Michael
Jul 20 '05 #1
2 5872
In article <99**************************@posting.google.com >,
Michael K?nig <ko****@gmail.com> 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
Jul 20 '05 #2
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
<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.
David
Jul 20 '05 #3

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

Similar topics

1
9421
by: Philipp Lenssen | last post by:
I have some chapters a document goes through, so at the end of each document I want to output "Continue with XYZ", where XYZ is the next-sibling of the current one I select. However I don't know...
7
2271
by: Bill Cohagan | last post by:
I have an XSLT transformation that involves a template with match = "w:p]" What I'm matching on is a w:p element that is: 1.) Within a w:body element (at some level). 2.) Immediately...
1
2861
by: paul.rusu | last post by:
XSLT: how to find 2nd next sibling?
11
2118
by: localpricemaps | last post by:
i have some html which looks like this where i want to scrape out the href stuff (the www.cnn.com part) <div class="noFood">Cheese</div> <div class="food">Blue</div> <a class="btn" href =...
3
2735
by: patrizio.trinchini | last post by:
Hi, how can remove sibling elements based on the value of an attribute ? For instance, gven the XML document: <root> <parentElment> <testElement name="A"> <removableElement/>
22
51404
by: ashkaan57 | last post by:
Hi, I am trying to put text on left and right side of the page and used: <div> <span>blah blah</span> <span style="float:right">blah blah</span> </div> The 2nd text does go to the right but the...
4
2754
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
12
3639
by: apicard | last post by:
I have a simple document like this: <Accept> <XXXX/> <Token image="From"/> <Date value="2007-01-01"/> <Token image="To"/> <Date value="2007-01-01"/> </Accept>
5
1736
by: Nathan Sokalski | last post by:
I'm not sure if this is the right place to ask this question, but I wasn't sure where else to go. I have a table made of the following tags: <table class="myclass"> <tbody> <tr><td>.</td></tr>...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.