Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with strategy for a peculiar muenchian grouping problem

From: "Anthony Jones" <Ant@------------.--->
To: 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




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent