How to Select the First/Last Sibling in XSLT

(0 votes, average 0 out of 5)

From my experiences with using XSL to transform XML documents, I frequently find the need to test the name of either the sibling directly following or directly preceding a given node.  Unfortunately, there is not XPATH expression that provides this functionality.  The following code should give you what you are looking for, however.

Check to see if the first preceding sibling is "car":

<xsl:if test="name(preceding-sibling::*[1]) = 'car'">
<!-- code to execute -->
</xsl:if>

Likewise, to test to see if the first following sibling is "car" use the following:

<xsl:if test="name(following-sibling::*[1]) = 'car'">
<!-- code to execute -->
</xsl:if>

Partner Links:
Last Updated on Tuesday, 20 July 2010 23:19  
Related Articles

» How to Find a Process Using a Particular Port in Linux

If you are trying to find the process using a particular port in Linux, you can do the following: lsof -i tcp:2700 The above example will return a list of processes using the TCP port with ID 2700.Alternatively you can view all open network connections by doing the following: sudo netstat -nlp 

» HTTP 1.1 Response Status Codes

When a request is sent to a web server, the web server will return a HTTP (HyperText Transfer Protocol) status code. These status codes are listed in five different categories, listed below:1XX - Informational2XX - Success3XX - Redirection4XX - Client Error5XX - Server ErrorThe complete list of status codes are listed below. All status codes are listed for the HTTP/1.1 standard.CodeNameDescription100ContinueThe server has received the request headers and the client should send the request body...

» How to connect an Apple Bluetooth Keyboard to Ubuntu (Troubleshooting)

Note: This guide uses programs specific to Ubuntu 10.04 (Lucid Lynx) and newer. For older versions of Ubuntu, please refer to .Sometimes the Ubuntu bluetooth stack can behave erratically and prevent you from connecting your Apple Bluetooth Keyboard (or other bluetooth device). The normal procedure for connecting your bluetooth keyboard involves the following steps:First, make sure the bluetooth applet is running by looking for the bluetooth icon on your panel:If it is not running, press ALT+F2,...