This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: xsl Date Sorting referencing ID and data in adifferentNode
- From: "KUMAR NINGASHETTY" <kningashetty at deltafunding dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 08 May 2002 15:59:54 -0400
- Subject: Re: [xsl] xsl Date Sorting referencing ID and data in adifferentNode
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello Joerg ..
Thanks for your inputs .. I just happened to try this ... It still doesnt seem to sort ...Here is the XSL i wrote
adopting your solution ,.....Please advise ...
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:key name="distinct-region" match="//company/application" use="region_name"/>
<xsl:key name="app-refs" match="//stages/application" use="@idref"/>
<xsl:template match="/">
<xsl:for-each select="//rep/company/application[generate-id()=generate-id(key('distinct-region', region_name))]">
<tr>
<xsl:value-of select="region_name"/>
</tr>
<xsl:for-each select="key('distinct-region', region_name)">
<xsl:sort select="key('app-refs',@id)/closedate" order="ascending"/>
<table>
<tr>
<td><xsl:value-of select="./@id"/> ~</td>
<td><xsl:value-of select="ssn"/> ~</td>
<td><xsl:value-of select="key('app-refs',@id)/closedate"/></td>
</tr>
</table>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
For XML:
<rep>
<company>
<application id="768">
<region_name><![CDATA[Region 4]]></region_name>
<company_name><![CDATA[ABC Inc.]]></company_name>
<ssn>234567890</ssn>
</application>
<application id="232">
<region_name><![CDATA[Region 4]]></region_name>
<company_name><![CDATA[BBC Inc.]]></company_name>
<ssn>112334556</ssn>
</application>
<application id="455">
<region_name><![CDATA[Region 2]]></region_name>
<company_name><![CDATA[CCC Inc.]]></company_name>
<ssn>667778559</ssn>
</application>
</company>
<stages>
<application idref="768">
<closedate>20020321</closedate>
<current>decline</current>
</application>
<application idref="232">
<closedate>20020411</closedate>
<current>cancel</current>
</application>
<application idref="455">
<closedate>20020227</closedate>
<current>decline</current>
</application>
</stages>
</rep>
Thanks everyone..
-Kumar
>>> joerg.heinicke@gmx.de 05/07/02 07:57PM >>>
Hello Kumar,
you can add a further key to easily access the application-elements with
closedate:
<xsl:key name="app-refs" match="stages/application" use="@idref"/>
With this key it's a bit easier to access the nodes, with which you want
to sort your application-elements.
And I would change your first key so, that you are directly getting the
application-element. I think the region_name is more or less
uninteresting, it's only for grouping.
At the end the stylesheet looks like:
<xsl:key name="distinct-region" match="company/application"
use="region_name"/>
<xsl:key name="app-refs" match="stages/application" use="@idref"/>
<xsl:template match="/">
<xsl:for-each
select="rep/company/application[generate-id()=generate-id(key('distinct-region',
region_name))]">
<xsl:value-of select="region_name"/>
<xsl:for-each select="key('distinct-region', region_name)">
<xsl:sort select="key('app-refs',@id)/closedate"/>
<xsl:value-of select="ssn"/>
<xsl:value-of select="key('app-refs',@id)/closedate"/>
<xsl:value-of select="key('app-refs',@id)/current"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
Regards,
Joerg
> XSL:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:key name="distinct-region" match="rep/company/application/region_name" use="text()"/>
> <xsl:template match="/">
> <xsl:for-each select="rep/company/application/region_name[generate-id()=generate-id(key('distinct-region', text()))]">
> <xsl:value-of select="text()"/>
>
>
> <xsl:for-each select="key('distinct-region', text())">
>
> <xsl:variable name="appid" select="parent::application/@id"/>
>
> <xsl:value-of select="parent::application/ssn"/>
> <xsl:value-of select="ancestor::rep/stages/application[@idref=$appid]/closedate"/>
> <xsl:value-of select="ancestor::rep/stages/application[@idref=$appid]/current"/>
>
> </xsl:for-each>
>
> </xsl:for-each>
> </xsl:stylesheet>
>
> </xsl:template>
>
>
> Thanks in advance ..
> -Kumar
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list