Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL variable question

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

I have the following situation:

I am using XSLT to transform the results of a SQL query to list all regions mapped to a certain salesperson. I need to list every region - with a checkbox to indicate if the particular region is actually mapped to that salesperson or not. I've got this far with minimal probs.

Now, what I need to do is, if the checkbox is checked (i.e. the region is mapped), I need to hyperlink the region name to a page displaying all the cities in the region. If it's not checked, I just need to display the name.

I've created an XSLT variable called 'checked' - and what I want to do is assign it a value of true or false based on the value of the checkbox. I know XSLT doesn't really support variables in the same way as a language like VB so is this actually possible? Am I making something very complicated of something that is actually quite simple? Or would I be better off doing this in code?

Here is my XSLT so far (with errors). Any ideas?

<xsl:template match=&quot;region&quot;>
<tr>
<td><xsl:value-of select=&quot;position()&quot;/>.</td>
<td></td>
<td>
<xsl:choose>
<xsl:when test=&quot;$UID=userid&quot;>
<input type=&quot;checkbox&quot; name=&quot;CheckMap
{position()}&quot; id=&quot;CheckMap{position()}&quot; checked=&quot;true&quot; />
<xsl:variable name=&quot;checked&quot; select=&quot;true&quot; />
</xsl:when>
<xsl:eek:therwise>
<input type=&quot;checkbox&quot; name=&quot;CheckMap{position()}&quot; id=&quot;CheckMap{position()}&quot; />
<xsl:variable name=&quot;checked&quot; select=&quot;false&quot; />
</xsl:eek:therwise>
</xsl:choose>
</td>
<input type=&quot;hidden&quot; id=&quot;ACID{position()}&quot; name=&quot;ACID{position()}&quot; value=&quot;{mapid}&quot; />
<td width=&quot;5&quot;></td>
<td><xsl:value-of select=&quot;id&quot; /></td>
<input type=&quot;hidden&quot; id=&quot;txtID{position()}&quot; name=&quot;txtID{position()}&quot; value=&quot;{id}&quot; />
<td width=&quot;5&quot;></td>
<td>
<xsl:choose>
<xsl:when test=&quot;$checked='true'&quot;>
<a href=&quot;./region.aspx?id={id}&quot;><xsl:value-of select=&quot;description&quot; /></a>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;description&quot; />
</xsl:eek:therwise>
</xsl:choose>
</td>
</tr>
</xsl:template>

This is just so everyone can see the logic that I'm trying to get at - I know this is wrong ;-)

Thanks as always

Craftor

:cool:
 
All I've done is debug your stylesheet.
Didn't have time to read everything you wrote, butthis should work.
Try it
............................................................

<xsl:template match=&quot;region&quot;>
<tr>
<td><xsl:value-of select=&quot;position()&quot;/>.</td>
<td></td>
<td>
<xsl:variable name=&quot;checked&quot;>
<xsl:choose>
<xsl:when test=&quot;$UID=userid&quot;>
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:eek:therwise>
<xsl:text>false</xsl:text>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>
<input type=&quot;checkbox&quot; name=&quot;CheckMap{position()}&quot; id=&quot;CheckMap{position()}&quot;>
<xsl:if test=&quot;$checked='true'&quot;>
<xsl:attribute name=&quot;checked&quot;/>
</xsl:if>
</input>
</td>
<input type=&quot;hidden&quot; id=&quot;ACID{position()}&quot; name=&quot;ACID{position()}&quot; value=&quot;{mapid}&quot; />
<td width=&quot;5&quot;></td>
<td><xsl:value-of select=&quot;id&quot; /></td>
<input type=&quot;hidden&quot; id=&quot;txtID{position()}&quot; name=&quot;txtID{position()}&quot; value=&quot;{id}&quot; />
<td width=&quot;5&quot;></td>
<td>
<xsl:choose>
<xsl:when test=&quot;$checked='true'&quot;>
<a href=&quot;../region.aspx?id={id}&quot;><xsl:value-of select=&quot;description&quot; /></a>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;description&quot; />
</xsl:eek:therwise>
</xsl:choose>
</td>
</tr>
</xsl:template>

............................................................
Build web applications faster with a few lines of XML Code using DataML[tm]
 
Hi whichman

Unfortunately it didn't work :-( not to worry I managed to find a workaround but thanks anyway!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top