Problem with xsl to make a text control disabled

Discussion in 'XML' started by eric.goforth@gmail.com, Aug 17, 2006.

  1. Guest

    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
    , Aug 17, 2006
    #1
    1. Advertising

  2. 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>
    Joe Kesselman, Aug 18, 2006
    #2
    1. Advertising

  3. 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.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Aug 18, 2006
    #3
  4. wrote:


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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 18, 2006
    #4
  5. Apparently I missed that part of the problem statement. Sigh. Sorry.
    Joseph Kesselman, Aug 18, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Romeyer Olivier
    Replies:
    12
    Views:
    10,943
  2. Replies:
    1
    Views:
    3,571
    A. Bolmarcich
    May 27, 2005
  3. jodleren
    Replies:
    3
    Views:
    847
    BootNic
    Oct 9, 2007
  4. alcatraz
    Replies:
    1
    Views:
    1,727
    alcatraz
    Apr 1, 2008
  5. JJ
    Replies:
    1
    Views:
    166
    Ken Schaefer
    Aug 20, 2003
Loading...

Share This Page