Welcome to WebmasterWorld Guest from 54.226.46.6

Forum Moderators: httpwebwitch

Message Too Old, No Replies

How do I use a variable within a path?

xsl path variable

     

sdcDan

4:13 pm on Oct 14, 2009 (gmt 0)

5+ Year Member



Hello, I am still new to xml and have ran into a slump with the following code.

<xsl:template name="compare">
<xsl:param name="i"/>
<xsl:param name="count"/>
<xsl:for-each select="../../client">
<td>
<xsl:value-of select="roam[$count]/@timing"/>
THIS STILL WORKS- <xsl:value-of select="$count"/>
</td>
</xsl:for-each>
</xsl:template>

<xsl:template match="/">
<table border="0" width="800px">
<xsl:for-each select="test/run/security/testCase/client[1]/roam">
<tr>
<td><xsl:number/></td>
<xsl:call-template name="compare">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="count"><xsl:number/></xsl:with-param>
</xsl:call-template>
</tr>
</xsl:for-each>
</table>
</xsl:template>

A sample of my xml is:

<?xml version="1.0" encoding="iso-8859-1"?>
<test>
<run>
<security>
<testCase id="Roam Test" len="20" num="10">

<client id="0">
<roam timing="11"></roam>
<roam timing="12"></roam>
<roam timing="13"></roam>
<roam timing="14"></roam>
<roam timing="15"></roam>
</client>

<client id="1">
<roam timing="21"></roam>
<roam timing="22"></roam>
<roam timing="23"></roam>
<roam timing="24"></roam>
<roam timing="25"></roam>
</client>

</testCase>
</security>
</run>
</test>

What I am looking for is it to create a column for client 1 and 2 with each row being a new roam. however even though count can be properly show with...

<xsl:value-of select="$count"/>

and...

<xsl:value-of select="roam[2]/@timing"/>

will select the second roam for each client...

<xsl:value-of select="roam[$count]/@timing"/>

will always display the first roams for both clients. Is there an easy syntax fix or a work around for this? Thanks in advanced!

sdcDan

5:05 pm on Oct 14, 2009 (gmt 0)

5+ Year Member



Of course after spending half a day looking for this, then swallowing my pride and asking for help if just figured it out...

<xsl:value-of select="roam[position()=$count]/@timing"/>

was what I was looking for

httpwebwitch

1:12 pm on Oct 15, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Right on sdcDan, that's how it's done. Thanks for posting the solution too, it will help others with the same problem who find this post.

Welcome to WebmasterWorld!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month