Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] multiple values for the key

From: "Mukul Gandhi" <gandhi.mukul@--------->
To:
Date: 8/2/2008 5:49:00 AM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent