Re: [xsl] genarate key using a variable

Subject: Re: [xsl] genarate key using a variable
From: "M. David Peterson" <conners_dad@xxxxxxx>
Date: Mon, 1 Sep 2003 02:26:08 -0600
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.chakrabarti@xxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
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


Current Thread