PDA

View Full Version : Getting the attribute from a previous node


wox3-iO
06-29-2003, 10:33 AM
I just started studying XML a few days back, and I'm now trying to make a list of (all) available IRC servers using XML. I've done pretty well so far, but now I'm facing anm annoying problem!

This is part of the huge XML file:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="servers-xsl-ext.xsl"?>

<servers_list>
<network pname="QuakeNet">
<server ports="6666-6668, 1500, 8080">
<name>b0rk.uk.quakenet.org</name>
<location>United Kingdom</location>
</server>
<server ports="6666-6669">
<name>barrysworld.uk.quakenet.org</name>
<location>United Kingdom</location>
</server>
<server ports="6666-6670, 7000">
<name>blueyonder.uk.quakenet.org</name>
<location>United Kingdom</location>
</server>
</network>
</servers_list>

This is from the XSL file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
...something here...
<table width="100%" border="0" cellspacing="2px" cellpadding="3px">
<tr style="background-color:#EEEEEE; font-family:Verdana,Arial; font-size:11px; color:#555555;">
<th align="left">Server name</th>
<th align="left">Location</th>
<th align="left">Ports</th>
</tr>
<xsl:for-each select="//server">
<xsl:sort select="location" data-type="text" order="ascending" case-order="lower-first"/>
<tr style="background-color:#F3F3F3; font-family:Verdana,Arial; font-size:10px; color:#555555;">
<td width="50%"><a href="irc://{name}"><xsl:value-of select="name"/></a></td>
<td width="25%"><xsl:value-of select="location"/></td>
<td width="25%"><xsl:value-of select="@ports"/></td>
</tr>
</xsl:for-each>
</table>

The problem is that I want the server ports, name, location and the "pname" attribute from the network element to be in the same table. This seems impossible to me... ALL help is appriciated! If there's something you don't understand, tell me. I'll try explaining it better.

jkd
06-29-2003, 06:28 PM
If <server/> is your context node, I want to say that you can do:

<xsl:value-of select="../@pname"/>

.... but it's been a while since I've done anything significant with XSLT.

wox3-iO
06-30-2003, 10:05 AM
Wow, it was that easy? Thank you, you're a life saver jkd!