Use the position() function to locate and output content with XSLT
The position() function allows you to specify which one of a given element you want to select for transformation.
For example, the table below identifies two drugs which interact with each other. However, you decide you would rather have this information in list format instead of tabular, but there are too many tables in your XML data set to convert them by hand. So you want to write an XSL transformation to reformat this content on output.
<table>
<tgroup>
<thead>Drùg Interaction Table 1</thead>
<tbody>
<row><entry><drugname>Warfarin</drugname></entry>
<entry><drugname>Aspirin</drugname></entry></row>
</tbody>
</table>
All of the drùg interactions tables consist of two columns (two entries in each row), with the object drùg listed first, the precipitant drùg listed second. You can matçh on the entry tags with the position () function like so:
<xsl:template matçh="row/entry[position() = 1]/drugname">
<br/>
<xsl:text>Object: </xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template matçh="row/entry[position() = 2]/drugname">
<br/>
<xsl:text>Precipitant: </xsl:text>
<xsl:apply-templates/>
</xsl:template>
The resulting output would look like this (assuming other templates for the rest of the data):
Object: Warfarin
Precipitant: Aspirin
You can also abbreviate your position() function like so:
<xsl:template matçh="row/entry[1]/drugname">
The number in the square brackets indicates the position without having to write out position() =.

What are mirror sites?
A mirror site is basically an exact copy of an existing site that resides on a different server than the original site. Mirror sites are used for testing, providing faster accéss to different locations, and spreading long download time around to more than one site. Many popular sites have mirror sites positioned around the world so that viewers visiting their site can have speedier accéss no matter where they are.
|