473,657 Members | 2,516 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>Ratzin ger</surname>
<profession>Pop e</profession>
</person>
I know what labels can appear ("Nombre:", "Apellido:","Po sició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:styleshe et 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:appl y-templates
select="td[text()='Nombre: ']"/></name>
<surname><xsl:a pply-templates
select="td[text()='Appelli do:']"/></surname>
<profession><xs l:apply-templates
select="td[text()='Posició n:']"/></profession>
</person>
</xsl:template>

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

<xsl:template match="td[text()='Appelli do:']">
<xsl:value-of select="followi ng-sibling::td" />
</xsl:template>

<xsl:template match="td[text()='Posició n:']">
<xsl:value-of select="followi ng-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 5884
In article <99************ **************@ posting.google. com>,
Michael K?nig <ko****@gmail.c om> wrote:
<xsl:template match="td[text()='Nombre: ']">
<xsl:value-of select="followi ng-sibling::td" />
</xsl:template>


You probably want:

<xsl:value-of select="followi ng-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="followi ng-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="followi ng-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
9430
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 how to write the XPath to express this. I tried variants of this with ASP/MSXML: sPhase = "foo" set xNext = xPhasesDoc.documentElement.selectSingleNode( "following-sibling::phase")
7
2288
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 preceeded by an aml:annotation element (whose @w:type is 'Word.Bookmark.Start').
1
2879
by: paul.rusu | last post by:
XSLT: how to find 2nd next sibling?
11
2139
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 = "http://www.cnn.com"> so i wrote this code which scrapes it perfectly:
3
2744
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
51494
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 next line. What am I doing wrong? TIA.
4
2776
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 (fromStop) and its associated driving directions back to a relational database. I have asked my software vendor for solutions but thus far they have not come up with anything. I am totally unfamiliar with XML so I am struggling with how to do this. I have...
12
3660
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
1755
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> <tr><td>.</td></tr> <tr><td>.</td></tr> </tbody> </table>
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8516
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
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 we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.