[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] effecient inline multi-conditional testing


Subject: Re: [xsl] effecient inline multi-conditional testing
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Nov 2001 12:02:02 -0500

Jeff:

If I understand you correctly, this is one way to do what you want. It uses an internal lookup table.

<local:true xmlns:local="local-namespace">
  <value>1</value>
  <value>true</value>
  <value>t</value>
  <!-- all your true values go in here -->
</local:true>

<xsl:template name="cast-boolean">
  <xsl:param name="b-value" select="'false'"/>
  <xsl:variable name="true-values" select="document('')/*/local:true/value"/>
  <xsl:choose>
    <xsl:when test="$b-value = $true-values">
      <!-- return true -->
    </xsl:when>
    <xsl:otherwise>
      <!-- return false -->
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Note that this approach is tolerant of unlisted values, returning false for them. It can be extended to be more choosy about these, however, by adding a second node set for the false values.

It works by using observing that in XPath, a string equals a node-set if its value equals the value of one of the nodes in the node set.

I'm not sure this is what you want, however: if not, please be more specific about what you mean by "cast". You want any of a set of values to resolve as true, correct? (And any of another set to resolve as false?)

Regards,
Wendell

At 08:41 AM 11/20/01, you wrote:
Dear <xsl-list:gurus/>,


here's the task: -create a template to cast an overloaded boolean value

here's the psuedo-template:
        <xsl:template name="cast:boolean">
                <xsl:param name="b-value">
                        <!-- overloaded boolean value;
                                some potential values may be:
                                        1.  'true' or 'false' or 't' or 'f'
                                        2.  'yes' or 'no' or 'y' or 'n'
                                        3.  '1' or '0'
                                        4.  ...
                          -->
                </xsl:param>
                <xsl:param name="cast">
                        <!-- 'casting' operator;
                                some potential values may be:
                                        1.  'true-false' or 't-f'
                                        2.  'yes-no' or 'y-n'
                                        3.  '1-0'
                                        4.  ...
                          -->
                </xsl:param>
                <xsl:if test="$operand">
                        <xsl:if
test="(($b-value='1')or($b-value='0')or($b-value='true')or($b-value='false')
or($b-value='yes')or($b-value='no') ... )">
                                <xsl:choose>
                                        <xsl:when
test="('true-false'=$cast)">
                                                <!-- ... -->

                                        </xsl:when>
                                        <xsl:when test="('yes-no'=$cast)">
                                                <!-- ... -->

                                        </xsl:when>
                                        <xsl:otherwise>
                                                <!-- ... -->
                                        </xsl:otherwise>

                                </xsl:choose>
                        </xsl:if>
                </xsl:if>
        </xsl:template>

my question is this:
Any ideas on a more effecient way to conduct the second (xsl:if) test than
the way I'm about to?


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords