xsl-list
[Top] [All Lists]

Re[2]: binary-or

2002-09-26 08:43:07

<xsl:value-of select="translate(string(number($operand1) + number($operand2)),
'2', '1')"/>

cool!

I like very much this implementation, it's much much more efficient than mine
and prevents the stack overflow that may happen with long input strings.

Thanks a lot!

============================== Original Message ==============================
From: Rubén
To: McNally, David
Date: Wednesday, September 25, 2002, 11:34:29 PM
Subject: [xsl] binary-or

I think this does what you want, though I didn't try all your test data.
It's not recursive - if that makes any difference.

<xsl:template name="or">
        <xsl:param name="operand1" select="''"/>
        <xsl:param name="operand2" select="''"/>
        <xsl:variable name="result1">
                <!-- would just return this if we didn't need to do the zero
padding -->
                <xsl:value-of select="translate(string(number($operand1) +
number($operand2)), '2', '1')"/>
        </xsl:variable>
        <xsl:choose>
                <xsl:when test="string-length($operand1) >
string-length($operand2)">
                        <xsl:value-of
select="concat(substring($operand1,1,(string-length($operand1) -
string-length($result1))),$result1)"/>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:value-of
select="concat(substring($operand2,1,(string-length($operand2) -
string-length($result1))),$result1)"/>
                </xsl:otherwise>
        </xsl:choose>
</xsl:template>

With some thought the xsl:choose could probable be improved.

HTH
David.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David(_dot_)McNally(_at_)Moodys(_dot_)com            (212) 553-7475

-----Original Message-----
From: Rubén [mailto:rubenm(_at_)telepolis(_dot_)com]
Sent: Wednesday, September 25, 2002 4:35 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] binary-or



Hello list! I couldn't find a "binary-or" (or "mask-or") 
operation in XPath 1.1 so I tried to
emulate it with a template. I wrote a recursive 
implementation but I'm not very
happy with the result. I wonder if there is a simpler (and 
maybe more efficient)
solution. Any suggestions?



---------------------------------------

The information contained in this e-mail message, and any attachment thereto, 
is confidential and may not be disclosed without our express permission.  If 
you are not the intended recipient or an employee or agent responsible for 
delivering this message to the intended recipient, you are hereby notified that 
you have received this message in error and that any review, dissemination, 
distribution or copying of this message, or any attachment thereto, in whole or 
in part, is strictly prohibited.  If you have received this message in error, 
please immediately notify us by telephone, fax or e-mail and delete the message 
and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, 
however, review this e-mail message, as well as any attachment thereto, for 
viruses.  We take no responsibility and have no liability for any computer 
virus which may be transferred via this e-mail message.


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

=========================== End Of Original Message ==========================


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



<Prev in Thread] Current Thread [Next in Thread>