Hi Mathieu,
use <xsl:sort select=... data-type="number"/>.
The default data-type is text:
1 < 2 < 3 < 6 results in 172 < ... < 68
Regards,
Markus
__________________________
Markus Abt
Comet Computer GmbH
http://www.comet.de
----------
Von: Wiepert, Mathieu
Gesendet: Donnerstag, 21. August 2003 22:29
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: [xsl] Unexpected sort order on a multi sort
Hi,
I am sure I am missing an obvious one here, but I am getting unexpected output,
based on the sort order. I stripped my XML down to the bare minimum here for
an example.
Output
SUBJECTS, Exp Var.Pos 172, Exp Var.Pos 202, Exp Var.Pos 236, Exp Var.Pos 316,
Exp Var.Pos 68
PA126746586, C/G, C/C, G/A, T/T, G/G
Expected the last variant to be the first based on sorting, since <position>
element is a number, shouldn't it be 68, 172, 202, 236, 316?
Do I have a strange typo? I added the number() function as a last stab, but I
was getting the same results without it? What did I miss!
Short XML DOC
<?xml version="1.0" encoding="UTF-8"?>
<pharmgkb xmlns="http://www.pharmgkb.org/schema/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pharmgkb.org/schema/
http://www.pharmgkb.org/schema/root.xsd">
<gene pharmgkbId="PA117">
<referenceSequence>
<dnaSequence>ccagTAAGCGCCCTCCTAATCCCCGCAGCGCCACC</dnaSequence>
<experiment>
<sampleSetXref
resource="PharmGKB">PA128747821</sampleSetXref>
<genotypesInSubject>
<subjectXref
resource="PharmGKB">PA126746586</subjectXref>
<pcrResult>
<assayXref
resource="local">21</assayXref>
<sequencedBothStrands>true</sequencedBothStrands>
<variant>
<position>202</position>
<firstAllele>C</firstAllele>
<secondAllele>C</secondAllele>
</variant>
<variant>
<position>68</position>
<firstAllele>G</firstAllele>
<secondAllele>G</secondAllele>
</variant>
<variant>
<position>172</position>
<firstAllele>C</firstAllele>
<secondAllele>G</secondAllele>
</variant>
<variant>
<position>236</position>
<firstAllele>G</firstAllele>
<secondAllele>A</secondAllele>
</variant>
<variant>
<position>316</position>
<firstAllele>T</firstAllele>
<secondAllele>T</secondAllele>
</variant>
</pcrResult>
</genotypesInSubject>
</experiment>
</referenceSequence>
</gene>
</pharmgkb>
XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="http://www.pharmgkb.org/schema/"
xmlns:sch="http://www.ascc.net/xml/schematron"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="text" indent="yes"/>
<!--index all the subject elements in doc by value of subjectXref-->
<xsl:key name="subject-key" match="//n1:subjectXref" use="."/>
<xsl:template match="/">
<!--get unique subjects -->
<xsl:variable name="unique-subjects"
select="//n1:subjectXref[generate-id(.)=generate-id(key('subject-key', .))]"/>
<!--loop on unique subjects-->
<xsl:for-each select="$unique-subjects">
<!--sort the subjects -->
<xsl:sort select="."/>
<xsl:if test="position()=1" >
<xsl:call-template name="procSubjectHeader"/>
</xsl:if>
<xsl:call-template name="procSubject"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="procSubjectHeader">
<xsl:variable name="subjectID" select="."/>
<!--Column name for the subjects -->
<xsl:text>SUBJECTS</xsl:text>
<!--get list of all variants for the subject -->
<xsl:variable name="subject-variants"
select="//n1:variant[../../n1:subjectXref=$subjectID]"/>
<xsl:for-each select="$subject-variants">
<!--Sort on all variants on experiment-->
<xsl:sort select="../../.."/>
<!--Sort on all variant position-->
<xsl:sort select="number(n1:position)"/>
<xsl:call-template name="procVariantHeader"/>
</xsl:for-each>
<!-- Output carriage return after all subject variants are
printed-->
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="procSubject">
<xsl:variable name="subjectID" select="."/>
<xsl:value-of select="$subjectID"/>
<!--get list of all variants for the subject -->
<xsl:variable name="subject-variants"
select="//n1:variant[../../n1:subjectXref=$subjectID]"/>
<xsl:for-each select="$subject-variants">
<!--Sort on all variants on experiment-->
<xsl:sort select="../../.."/>
<!--Sort on all variant position-->
<xsl:sort select="n1:position"/>
<xsl:call-template name="procVariant">
<!--xsl:with-param name="variant" select="."/-->
</xsl:call-template>
</xsl:for-each>
<!-- Output carriage return after all subject variants are
printed-->
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="procVariantHeader">
<xsl:text>, Exp Var.Pos </xsl:text>
<xsl:value-of select="n1:position"/>
</xsl:template>
<xsl:template name="procVariant">
<xsl:value-of select="concat(',
',n1:firstAllele,'/',n1:secondAllele)"/>
</xsl:template>
</xsl:stylesheet>
Thanks,
-mat
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list