xsl-list
[Top] [All Lists]

Re: genarate key using a variable

2003-09-01 01:26:08
I forgot that I needed to send this message in plain text format.  If the 
other one gets through I apologize for the repeat mail...

Original text of my email....

Hey Aruniima,

You've stumbled upon one that puzzled me for awhile.  But I finally came up 
with a quick and easy workaround.  Im sure there are others but this one is 
simple and it works which are my number one rules of coding.

My assumption is that the number of choices the user has as far as node 
names is fairly limited (e.g. Deposits, Withdrawls, etc...) and as such it 
should be a quick and easy task for the xsl:choose element...

heres the xml file...

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="transactions.xslt" ?>
<transactions>
    <deposits>
        <deposit id="001">25.00</deposit>
        <deposit id="002">25.00</deposit>
        <deposit id="003">35.00</deposit>
        <deposit id="004">10.00</deposit>
        <deposit id="005">12.00</deposit>
        <deposit id="006">25.00</deposit>
        <deposit id="007">25.00</deposit>
    </deposits>
    <withdrawals>
        <withdrawal id="001">5.00</withdrawal>
        <withdrawal id="002">2.00</withdrawal>
        <withdrawal id="003">5.00</withdrawal>
        <withdrawal id="004">10.00</withdrawal>
        <withdrawal id="005">12.00</withdrawal>
        <withdrawal id="006">250.00</withdrawal>
        <withdrawal id="007">250.00</withdrawal>
    </withdrawals>
</transactions>



and heres the related xslt file named transactions.xslt....  just change the 
variables accordingly


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >

<xsl:variable name="var_1">deposit</xsl:variable>
<xsl:variable name="var_2">25.00</xsl:variable>
<xsl:key name="varMatch_Deposit" match="//deposit" use="."/>
<xsl:key name="varMatch_Withdrawal" match="//withdrawal" use="."/>

    <xsl:template match="/">

    <xsl:choose>
        <xsl:when test="$var_1 = 'deposit'">

            <xsl:for-each select="key('varMatch_Deposit', $var_2)">

                Deposit ID: <xsl:value-of select="@id"/><br/>
                Amount: <xsl:value-of select="."/><br/><br/><hr/>

            </xsl:for-each>

        </xsl:when>
        <xsl:when test="$var_1 = 'withdrawal'">

            <xsl:for-each select="key('varMatch_Withdrawal', $var_2)">

                Other ID: <xsl:value-of select="@id"/><br/>
                Other Amount: <xsl:value-of select="."/><br/><br/><hr/>

            </xsl:for-each>

        </xsl:when>
        <xsl:otherwise>

            //code for otherwise

        </xsl:otherwise>
    </xsl:choose>

    </xsl:template>
</xsl:stylesheet>


Hope this helps.

Best of luck!

M.David




----- Original Message ----- 
From: <aruniima(_dot_)chakrabarti(_at_)iflexsolutions(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Monday, September 01, 2003 12:16 AM
Subject: [xsl] genarate key using a variable


Hi All,
Is it possible to generate a xsl:key using a variable ?
As in  xsl:key element it does not allow me to use a variable in either 
match or use attribute. So is there any other way to do the same...

e.g.
I want to search for all Rows with attribute say "@Deposit = 1"
where I receive both the attribute & the attribute value as parameters 
from the user.



Regards,
aruniima



DISCLAIMER:
This message contains privileged and confidential information and is 
intended only for the individual named.If you are not the intended 
recipient you should not disseminate,distribute,store,print, copy or 
deliver this message.Please notify the sender immediately by e-mail if you 
have received this e-mail by mistake and delete this e-mail from your 
system.E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted,corrupted,lost,destroyed,arrive late 
or incomplete or contain viruses.The sender therefore does not accept 
liability for any errors or omissions in the contents of this message 
which arise as a result of e-mail transmission. If verification is 
required please request a hard-copy version.

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



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



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