Welcome to WebmasterWorld Guest from

Forum Moderators: httpwebwitch

Message Too Old, No Replies

How do I use a variable within a path?

xsl path variable

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

New User

5+ Year Member

joined:Oct 14, 2009
posts: 2
votes: 0

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">
<xsl:value-of select="roam[$count]/@timing"/>
THIS STILL WORKS- <xsl:value-of select="$count"/>

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

A sample of my xml is:

<?xml version="1.0" encoding="iso-8859-1"?>
<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 id="1">
<roam timing="21"></roam>
<roam timing="22"></roam>
<roam timing="23"></roam>
<roam timing="24"></roam>
<roam timing="25"></roam>


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"/>


<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!

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

New User

5+ Year Member

joined:Oct 14, 2009
votes: 0

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

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

Moderator This Forum from CA 

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

joined:Aug 29, 2003
votes: 0

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!