[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Break functionality in XSL


Subject: Re: [xsl] Break functionality in XSL
From: Anil Kumar Veeramalli <anil.v@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 18 Nov 2009 19:15:51 +0530

Hi,

is this possible to have a key with two attributes.

<xsl:key name="k1" match="ROW" use="COLUMN[@NAME = 'JOBCODE'],COLUMN[@NAME = 'JC_CODE']"/> like this?

Please suggest me on this.

-Anil



Anil Kumar Veeramalli wrote:
Thanks a lot Martin.
-Anil
Martin Honnen wrote:
You can define a key on the ROW elements:
<xsl:key name="k1" match="ROW" use="COLUMN[@NAME = 'JOBCODE']"/>
then key('k1', 'P10') gives you a node-set of the ROW elements with that key value, then you can sort that by the date in descending order and only take the description of the first ROW:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:data="http://example.com/2009/data"
  exclude-result-prefixes="data"
  version="1.0">

<xsl:param name="jobcode" select="'P10'"/>

<xsl:key name="k1" match="ROW" use="COLUMN[@NAME = 'JOBCODE']"/>

<xsl:output method="text"/>

  <data:data xmlns="">
    <month key="Jan" value="01"/>
    <month key="Feb" value="02"/>
    <month key="Mar" value="03"/>
    <month key="Apr" value="04"/>
    <month key="May" value="05"/>
    <month key="Jun" value="06"/>
    <month key="Jul" value="07"/>
    <month key="Aug" value="08"/>
    <month key="Sep" value="09"/>
    <month key="Oct" value="10"/>
    <month key="Nov" value="11"/>
    <month key="Dec" value="12"/>
  </data:data>

<xsl:template match="/">
<xsl:for-each select="key('k1', $jobcode)">
<xsl:sort select="concat(
substring(COLUMN[@NAME = 'EFFDT'], 8, 4),
'-',
document('')/xsl:stylesheet/data:data/month[@key = substring(COLUMN[@NAME = 'EFFDT'], 4, 3)]/@value,
'-',
substring(COLUMN[@NAME = 'EFFDT'], 1, 2))"
order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="COLUMN[@NAME = 'DESCR']"/>
</xsl:if>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>


The only problem is dealing with that date format, you can't sort on that directly, you need to extract the components and bring them into a yyyy-mm-dd format that can be sorted as a string. The stylesheet above does that.


Current Thread