[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: multiple values for the key

Subject: Re: multiple values for the key
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 2 Aug 2008 11:18:24 +0530
Re:  multiple values for the key
David, has given one possible solution, in XSLT 1.0 (which has
advantage, that you don't need to use any extension function). Mike
gave you a XSLT 2.0 version (which I feel, is cool).

Based on Mike's idea, here is another version using node-set extension
function in XSLT 1.0,

(this runs on the XML you posted)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                       xmlns:exslt="http://exslt.org/common"
                       exclude-result-prefixes="exslt"
                       version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:key name="x" match="subroot" use="ccc"/>

<xsl:variable name="x-values">
  <v>11</v>
  <v>22</v>
</xsl:variable>

<xsl:template match="/root">
  <result>
    <xsl:for-each select="key('x', exslt:node-set($x-values)/v)">
      <value>
        <xsl:value-of select="eee" />
      </value>
    </xsl:for-each>
  </result>
</xsl:template>

</xsl:stylesheet>

I think, this could be better than David's version, because if you
want to have pretty large no. of different values to search by the
key, you just have to change this part,

<xsl:variable name="x-values">
  <v>11</v>
  <v>22</v>
  <!-- more values -->
</xsl:variable>


On Thu, Jul 31, 2008 at 9:58 PM, sudheshna iyer <sudheshnaiyer@xxxxxxxxx> wrote:
> How do I use multiple key values?
>
> Declaration:
> <xsl:key name="keyname" match="subroot" use="ccc"/>
>
> During the usage, I want to specify multiple values:
>
> <xsl:variable name="keyname" select="key('keyname', '11' or '22')"/> ==>  Here I want to use multiple values 11 and 22.
>
> For the following xml, result should be:
> aaaaa bbbbb ccccc ddddd ==> note that both values of  ccc= '22' and ccc= '11'
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>    <subroot id="11111">
>        <ccc>11</ccc> ==> needs to be picked
>        <ddd>2005-08-26</ddd>
>        <eee>aaaaa</eee>
>    </subroot>
>    <subroot id="11111">
>        <ccc>22</ccc> ==> needs to be picked
>        <ddd>2005-08-26</ddd>
>        <eee>bbbbb</eee>
>    </subroot>
>    <subroot id="11111">
>        <ccc>11</ccc>
>        <ddd>2005-08-26</ddd>
>        <eee>ccccc</eee>
>    </subroot>
>    <subroot id="11111">
>        <ccc>11</ccc>
>        <ddd>2005-08-26</ddd>
>        <eee>ddddd</eee>
>    </subroot>
>    <subroot id="11111">
>        <ccc>33</ccc>
>        <ddd>2005-08-26</ddd>
>        <eee>eeeee</eee>
>    </subroot>
> </root>
>
> Thank you for your help.


-- 
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.