XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Atif SarfrazSubject: XSL Template problem
Author: Atif Sarfraz
Date: 26 Nov 2001 08:45 PM
Hi,

I have created an XSL template to automatically check a radio button depending upon some value of XML. So if there is a group of 5 radio buttons, then depending upon the value of XML field, one of them would be checked.

The template works fine with one group of radio buttons. But if I start calling the same template from another group, with a different "name", then the first group and the second group of radio buttons behave as they belonged to the same group.

Here is the template code

{xsl:template name='radioButtonTemplate' }
{xsl:param name='arg1' select='/' /}
{xsl:param name='arg2' /}
{xsl:param name='arg3' /}

{xsl:if test="$arg1=$arg2"}
{input type="radio" checked="" name=""}
{xsl:attribute name="value"}$arg1{/xsl:attribute}

{xsl:attribute name="name"}$arg3{/xsl:attribute}
{/input}

{/xsl:if}
{xsl:if test="$arg1!=$arg2"}
{input type="radio" name=""}
{xsl:attribute name="value"}$arg1{/xsl:attribute}

{xsl:attribute name="name"}$arg3{/xsl:attribute}
{/input}
{/xsl:if}

{/xsl:template}


I am calling the template with the following code.

{xsl:call-template name='radioButtonTemplate' }
{xsl:with-param name='arg1' }Other{/xsl:with-param}
{xsl:with-param name='arg2' select='HSCROOT/MORTGAGEDATA/PRODUCT/@MortgageType' /}
{xsl:with-param name='arg3' }MortgageType{/xsl:with-param}
{/xsl:call-template}

What I feel is that arg2 behaves like a sort of a global variable, and on changing the group of radio buttons, the first one also gets effected.

Am I correct? Is there a way out of it? Or should I create separate templates for each group of radio buttons.

Postnext
Minollo I.Subject: Re: XSL Template problem
Author: Minollo I.
Date: 26 Nov 2001 09:23 PM
I would guess that your problems are caused by this and similar blocks:

>...
>{input type="radio" checked="" name=""}
>{xsl:attribute name="value"}$arg1{/xsl:attribute}
>{xsl:attribute name="name"}$arg3{/xsl:attribute}
>{/input}
>...

At least in the Stylus Studio processor, trying to re-define the value of
an attribute already defined in the parent element is a no-op (I searched
the specs trying to understand what the right behavior should be, but I
couldn't find this case covered...).
That means that the name of the radio buttons would end-up being always the
same (empty) explaining the behavior you are describing.
If that's the problem, the fix is very easy: just remove 'name=""' from
your {input} element creation.

>...
>What I feel is that arg2 behaves like a sort of a global variable, and on
>changing the group of radio buttons, the first one also gets effected.
>
>Am I correct? Is there a way out of it? Or should I create separate
>templates for each group of radio buttons.

No, template parameters are not global variables; you should expect the
named template to be called with a different set of parameter values every
time it's called.

Minollo

Postnext
Atif SarfrazSubject: XSL Template problem
Author: Atif Sarfraz
Date: 27 Nov 2001 10:01 AM
Hi,

I have checked the code again, and even if I remove the name attribute from the top element, the code still doesn't work. It only works only if I remove all the name attributes including the new ones.

{xsl:if test="$arg1=$arg2"}
{input type="radio" checked=""}
{xsl:attribute name="value"}$arg1{/xsl:attribute}
{/input}
{/xsl:if}

Now there is only one option selected in each group of radio buttons. However the problem, is that I can't now select any other radio button.

I have checked the HTML Code, and what I see is that the $arg1 doesn't assigns the value, but the string $arg1 itself. So the html shows

{input type="radio" checked value="$arg1" name="$arg3"}

What Tag should I use to assign the value of $arg1?

Posttop
Atif SarfrazSubject: XSL Template problem
Author: Atif Sarfraz
Date: 27 Nov 2001 10:17 AM
Oh I got it, the correct way to put the value was

{xsl:attribute name="name"}{xsl:value-of select='$arg3' /}{/xsl:attribute}

So its working fine now.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.