Using the Oracle XE sample database I wanted to produce a table of customers where - if the customer have one or more contacts or orders - I wanted a link to a list of those, passing the CUSTOMER_ID as a GET (query_string) variable. Here's how...
Here's a sample of the XML, obtained from Oracle's DBMS_XMLGEN.getXML function...
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
<ROW>
<CUSTOMER_ID>177</CUSTOMER_ID>
<NAME>United Continental Holdings</NAME>
<ADDRESS>2904 S Salina St, Syracuse, NY</ADDRESS>
<WEBSITE>http://www.unitedcontinentalholdings.com</WEBSITE>
<CREDIT_LIMIT>5000</CREDIT_LIMIT>
<ORDERS>0</ORDERS>
<CONTACTS>1</CONTACTS>
</ROW>
<ROW>
<CUSTOMER_ID>180</CUSTOMER_ID>
<NAME>INTL FCStone</NAME>
<ADDRESS>5344 Haverford Ave, Philadelphia, PA</ADDRESS>
<WEBSITE>http://www.intlfcstone.com</WEBSITE>
<CREDIT_LIMIT>5000</CREDIT_LIMIT>
<ORDERS>2</ORDERS>
<CONTACTS>1</CONTACTS>
</ROW>
</ROWSET>
Here's the style sheet...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="ROWSET/ROW">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<!-- these nodes have specific behaviour -->
<xsl:template match="ORDERS">
<td>
<xsl:if test=". > 0">
<!-- here's the anchor tag -->
<a href="/Orders?CUSTOMER_ID={../CUSTOMER_ID}"><xsl:value-of select="."/></a>
</xsl:if>
</td>
</xsl:template>
<xsl:template match="CONTACTS">
<td>
<xsl:if test=". > 0">
<a href="/Contacts?CUSTOMER_ID={../CUSTOMER_ID}"><xsl:value-of select="."/></a>
</xsl:if>
</td>
</xsl:template>
<!-- all other node are just displayed as a cell -->
<xsl:template match="*">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
Rendered as HTML, the anchors look like this...
http://localhost:8080/Orders?CUSTOMER_ID=184