homepage Welcome to WebmasterWorld Guest from 54.204.249.184
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
How do I use a variable within a path?
xsl path variable
sdcDan




msg:4006939
 4:13 pm on Oct 14, 2009 (gmt 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">
<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




msg:4006985
 5:05 pm on Oct 14, 2009 (gmt 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

httpwebwitch




msg:4007539
 1:12 pm on Oct 15, 2009 (gmt 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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved