I am trying to do a XSL transformation on an XML document of all the bus routes and bus stops within my city. In doing so I'm using a for-each select that selects all the "stop" nodes that contain the route number I'm passing in as a parameter.
When I go to run my program, none of the values seem to be getting selected and I am wondering if my syntax is invalid or can you not use parameters in an xsl:for-each select statement?
Here is my xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="route_num"></xsl:param>
<xsl:param name="num_stops" />
<xsl:template match="/">
<!-- ... -->
<xsl:for-each select="allstops/stop[contains(routes,$route_num)]">
<xsl:sort select="@number"/>
<tr>
<td><xsl:value-of select="@number"/></td>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="location/latitude"/></td>
<td><xsl:value-of select="location/longitude"/></td>
<td><xsl:value-of select="routes"/></td>
</tr>
</xsl:for-each>
<!-- ... -->
</xsl:template>
</xsl:stylesheet>
And here is a sample of the XML:
<stop number="20" name="Adelaide & Ada NB">
<location>
<latitude>42.9742886</latitude>
<longitude>-81.2252341</longitude>
</location>
<routes>16</routes>
</stop>
So lets say an XML node contains a route of 16, it should go through all the nodes and pull the data into the fields I have set up, unless my syntax is wrong with the XSL should it not?
EDIT: the routes tag can contain multiple route numbers, which is why I have been using contains:
<stop number="408" name="Clarence & King St NB">
<location>
<latitude>42.9835093</latitude>
<longitude>-81.2471596</longitude>
</location>
<routes>05, 09, 12, 19, 23</routes>
</stop>
EDIT #2: XML has no namespaces.
contains(concat(',', translate(routes, ' ', ''), ','), contcat(',', $route_num, ',')). Yes, that's ugly, but that's direct a consequence of using XML wrong. - Tomalak