This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

xsl Date Sorting referencing ID and data in a different Node


Hi,

    Given a straight xml and with no ID and IDref's to refer i can Sort end result Datewise .
    IN the following XML i am having problem to sort by 'closedate' which is in  different node .
    In my XSL i use keys to group the data by Regions and display corresponding data beneath ..
    It seems to be little tricky to sort by <closedate> which is child of <stages> node by preserving 
    the exsiting key technique .
   Note : if the <closedate> is part of  /company/application then i am able to sort it though ...

  Any help appreciated ..

    Following is the XML and XSL i am having presently ...

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 4]]></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 appsysidref="455">
	    <closedate>20020227</closedate>
	    <current>decline</current>
	</application>
 </stages>
</rep>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]