Re: [xslt] using key() function with key name in a variable

>   Seems very easy to fix to follow the common behaviour, so it's 
probably not
> worth starting a standard reading contest over xsl-list :-)
>   Patch enclosed, untested since you didn't provided a full example.

Thanks very much -- I can confirm it works.  Sorry about the lack of an 
example, but maybe better late than never:

source doc: --------------------
  <list type="one"/>
  <list type="two"/>
    <entry cat1="a" cat2="a" qty="1"/>
    <entry cat1="a" cat2="b" qty="2"/>
    <entry cat1="b" cat2="b" qty="3"/>

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

<xsl:template match="/">

<xsl:key name="k1" match="entry" use="@cat1"/>
<xsl:key name="k2" match="entry" use="@cat2"/>

<xsl:template match="list">
  <xsl:variable name="k">
      <xsl:when test="@type='one'">k1</xsl:when>
    <type><xsl:value-of select="@type"/></type>
    <a><xsl:value-of select="sum( key($k,'a')/@qty )"/></a>
    <b><xsl:value-of select="sum( key($k,'b')/@qty )"/></b>
<xsl:template match="entries"/>

output: -----------------------
<?xml version="1.0"?>


Thanks again, John Escott.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]