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

[xsl] Complex sorting problem (looking for an XSLT outer join?)


Subject: [xsl] Complex sorting problem (looking for an XSLT outer join?)
From: Taras Tielkes <taras@xxxxxxx>
Date: Thu, 16 Jan 2003 18:43:40 +0100

Hi,

My source xml has the following format:

<root>
    <items>
        <item category="1" data="ggg">
            <date year="1995" month="4" day="13"/>
        </item>
        <item category="2" data="hhh">
            <date year="1984" month="7" day="22"/>
        </item>
        <item category="3" data="www">
            <date year="1991" month="3" day="12"/>
        </item>
        <item category="3" data="rrr">
            <date year="1999" month="6" day="19"/>
        </item>
        <item category="4" data="xxx">
            <date year="1982" month="2" day="17"/>
        </item>
        <item category="5" data="kkk">
            <date year="2000" month="12" day="11"/>
        </item>
    </items>
    
    <categories>
        <category id="1" weight="0">
        <category id="3" weight="2">
        <category id="4" weight="1">
    </categories>
</root>

1) The source xml contains a list of items.
   Each item carries a 'data' attribute, which is the actual content of the
item.
   Apart from that, each item contains:
   a) a 'catagory' attribute, identifying the catagory that the item belogs
to.
   b) a 'date' child element, representing the date of the item
   Each item has an implied weight, implied by the category that it
references. (but see [2] and [3])
   
2) The source xml also contains a list of categories.
   Each category contains a 'weight' attribute, which carries the
'importance' of the category.
   Weight is from 0 (least important) to 2 (most important), in other words
[0,2].
   
3) Some of the categories referred to by the item elements are not present
in the source xml.
   A default weight of 1 should be assumed in that case.
   In the example xml, the categories (2,5) are absent.
       
I would like to sort the item elements using the following criteria:
   1) first, by (implied) weight
   2) second, by date
   
It seems to me that the problem would be easy if all referenced categories
were present in the source xml.
In that case, I could use xsl:key to retreive the matching weight for each
item.

However, that is not the case. It seems that what I want is to grab a
default weight of 1 wherever the references category is not present in the
source xml.
Using SQL, for instance, I could use an outer join, specifying a default
value.
    
Is there any solution for this problem in XSLT?
    
Thanks in advance for any feedback,
    
tt





   

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml