Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Help with strategy for a peculiar muenchian grouping problem [Thread Next] Re: Help with strategy for a peculiar muenchian grouping problemTo: NULL Date: 6/2/2006 1:55:00 PM
<mike.renwick@u...> wrote in message
news:1149165363.584372.161000@y......
> Hi all,
>
> I've got a bit of a head scratcher here.
>
> Basically I've got an XML file with items in it like so
>
> <item>
> <name>Valuable1_a</name>
> <amount>10</amount>
> </item>
> <item>
> <name>Valuable1_b</name>
> <amount>10</amount>
> </item>
> <item>
> <name>Valuable2</name>
> <amount>10</amount>
> </item>
> <item>
> <name>Valuable2_a</name>
> <amount>10</amount>
> </item>
>
> And I'm trying to roll up the amounts to leave me with
> Valuable1 20
> Valuable2 20
>
> Basically I'd need to do a "group by" on unique names (excluding any
> suffixes if there are any).
>
> I've tried various ways
> -Creating a temp tree and setting up a muenchian group on that
> -can't seem to do this in MSXML
>
> -Setting up to groups, one for items with second last character "_",
> one for everything else
>
> <xsl:key name="ikey1"
> match="item[substring(name,string-length(name)-1,1)='_']"
> use="substring(name,1,string-length(name)-2)"/>
>
> <xsl:variable name = "unq"
>
select="item[generate-id(.)=generate-id(key('ikey1',substring(name,1,string-
length(name)-2)))]/name\"/>\n"
>
> and then the same but this time where the second last character != "_"
>
> But it creates duplicates.
> I can't work out how to do this given
> -You can't create a muenchian group on a calculated bit of xml
> -You can't seem to do a conditional i.e. (condition) ? (if true) : (if
> false) type statement in the key setup
> -I don't know how to combine two unique lists to create a single unique
> list if there are possibly things in common between them?
>
> Thoughts on a strategy anyone?
>
> -Most confused Mike.
TBH I'd be inclined to simply preprocess the XML adding '_temp' to any name
not already containing an _ then using this xsl:-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" />
<xsl:key name="items" match="item" use="substring-before(name,'_')" />
<xsl:template match="items">
<table rules="all">
<thead>
<tr>
<th>Name</th><th>Total</th>
</tr>
</thead>
<xsl:for-each select="item[count(key('items',
substring-before(name,'_'))[1] | .) = 1]">
<tr>
<td><xsl:value-of select="substring-before(name,'_')" /></td>
<td><xsl:value-of select="sum(key('items',
substring-before(name,'_'))/amount)" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
OR better yet simply add a 'group' attribute to the item element to elminate
the need for the substring stuff in the XSL.
Anthony
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
