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

Re: Break functionality in XSL

Subject: Re: Break functionality in XSL
From: Anil Kumar Veeramalli <anil.v@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 03 Nov 2009 15:41:31 +0530
Re:  Break functionality  in XSL
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

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-2013 All Rights Reserved.