Problem with xsl to make a text control disabled

E

eric.goforth

Hello,

I'm getting:

msxml3.dll (0x80004005)
Error while parsing "file:///c:/WWWROOT/includes/Inc.xsl". A name was
started with an invalid character.

When I put in the "{$sDisabledString}"

<xsl:param name="sName"></xsl:param>
<xsl:param name="sValue"></xsl:param>
<xsl:param name="sAction"></xsl:param>
<xsl:param name="sDisabled"></xsl:param>
<xsl:param name="nMaxLength"></xsl:param>
<xsl:param name="nSize"></xsl:param>

<xsl:choose>
<xsl:when test="$sDisabled = 'Yes' or $sDisabled = '1' or $sDisabled
='True'">
<xsl:variable name="sDisabledString">disabled=""
style="background-color:#e8e8e8;"</xsl:variable>
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name="sDisabledString"></xsl:variable>
</xsl:eek:therwise>
</xsl:choose>


<INPUT TYPE="text" SIZE="{$nSize}" MAXLENGTH="{$nMaxLength}"
NAME="{$sName}" VALUE="{$sValue}" "{$sDisabledString}"
onblur="{$sAction}"></INPUT>

Why can't I put in a name value pair (or pairs) in a variable like
this?

-Eric
 
J

Joe Kesselman

It would help if you gave us a stand-alone runnable example that
provokes the problem, rather than a fragment. I'm not sure what you mean by
When I put in the "{$sDisabledString}"


The following compiles and runs happily. If it breaks on your system,
get a newer/more-trustworthy XSLT processor. If it doesn't break, maybe
comparing it with your real code will help you figure out what you're
doing wrong.

One important point: Remember that variables are defined ONLY within the
scope of the element their declaration appears in. $sDisabledString can
not be referenced outside the when or otherwise case that sets it. If
that's what you're trying to do, you need to turn the code inside out,
using the choose to compute the value inside the xsl:variable's
initialization rather than trying to set the variable within the choose
cases.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="foo">
<xsl:param name="sDisabled"></xsl:param>
<xsl:choose>
<xsl:when test="$sDisabled = 'Yes' or $sDisabled = '1' or $sDisabled
='True'">
<xsl:variable name="sDisabledString">disabled=""
style="background-color:#e8e8e8;"</xsl:variable>
First case: The string has been set to [<xsl:value-of
select="$sDisabledString"/>]
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name="sDisabledString"></xsl:variable>
Second case: The string has been set to [<xsl:value-of
select="$sDisabledString"/>]
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

<xsl:template match="/">
<xsl:call-template name="foo">
<xsl:with-param name="sDisabled">Yes</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="foo">
<xsl:with-param name="sDisabled">foo</xsl:with-param>
</xsl:call-template>
</xsl:template>


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text>
</xsl:text>
</xsl:template>


</xsl:stylesheet>
 
J

Joe Kesselman

Joe Kesselman wrote:
By the way, you can ignore the last template,
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text>
</xsl:text>
</xsl:template>

.... that was left over from a previous example.
 
M

Martin Honnen

msxml3.dll (0x80004005)
Error while parsing "file:///c:/WWWROOT/includes/Inc.xsl". A name was
started with an invalid character.
<INPUT TYPE="text" SIZE="{$nSize}" MAXLENGTH="{$nMaxLength}"
NAME="{$sName}" VALUE="{$sValue}" "{$sDisabledString}"
onblur="{$sAction}"></INPUT>

Why can't I put in a name value pair (or pairs) in a variable like
this?

Your XSLT stylesheet needs to be well-formed XML and e.g.
VALUE="{$sValue}"
to define an attribute in the start tag of an element is well-formed but
putting in e.g.
"{$sDisabledString}"
is not well-formed.
The {XPathexpression} syntax is called attribute value template so you
can use it in attribute values to generate the attribute value or part
of it, the syntax is not available outside of attribute values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top