473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Filter a Muenchian Group

Hello,

I am trying to filter a Muenchian grouping I have created. I think I am
fairly close, but I am not quite sure where to apply my filter; its
been some time since I did any work with XSLT. An example of my XML;

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Structure.xsl" type="text/xsl"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata">
<CostCentre>
<ServiceOrder>1</ServiceOrder>
<Service>Directorate Management Team</Service>
<ServiceDivisionOrder>10</ServiceDivisionOrder>
<ServiceDivisionName>DMT</ServiceDivisionName>
<SectionOrder>A</SectionOrder>
<Section>Service Management and Development</Section>
<CostCentreID>6000</CostCentreID>
</CostCentre>
<CostCentre>
<ServiceOrder>2</ServiceOrder>
<Service>Commissioning and Partnership Services</Service>
<ServiceDivisionOrder>20</ServiceDivisionOrder>
<ServiceDivisionName>Commissioning and Partnership
Services</ServiceDivisionName>
<SectionOrder>A</SectionOrder>
<Section>Commissioning and Partnerships</Section>
<CostCentreID>600N</CostCentreID>
</CostCentre>

There are several cost centres in each section, several sections in
each service division and several service divisions in each service. I
would like to group by service, service division and then section. So
far I have managed to get the following XSL;

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="AllServices" match="CostCentre" use="Service"/>
<xsl:key name="AllServiceDivisions" match="CostCentre"
use="concat(Service ';' ServiceDivisionName)"/>
<xsl:template match="/">
<html>
<body>
<ol>
<xsl:for-each
select="//CostCentre[generate-id(.)=generate-id(key('AllServices',Service))]">
<xsl:sort select="ServiceOrder" data-type="number" />
<li><xsl:value-of select="Service" /></li>
<xsl:variable name="currentService">
<xsl:value-of select="Service"/>
</xsl:variable>
<ul>
<xsl:for-each
select="//CostCentre[generate-id(.)=generate-id(key('AllServiceDivisions',concat(Service
';' ServiceDivisionName)))] ">
<xsl:sort select="ServiceDivisionOrder" data-type="number" />
<li><xsl:value-of select="ServiceDivisionName" /></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</ol>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I *think* I have made the variable correctly, but am I totally lost at
where to apply the filter (using $currentService). Currently, as you
can imagine, I get all service divisions in each service, rather than
just the service divisions for that service. I have tried several
syntaxes and several locations but with no such luck. Once I get this
right, I believe I can crack the rest. Can anyone shed any light on
where and how I should apply the filter??? Thanks.

Dec 6 '06 #1
2 1501
It'd help if you'd been a bit more specific about how you wanted to
filter this. Since you said you want to filter based on $currentService,
and that's being set from the value of the <Serviceelement, I presume
your goal is to select only those <CostCentre>s which have a particular
<Servicevalue.

There are multiple ways you can do this. For example, you might apply
that filtering before you spend time sorting. You can do that by simply
replacing all references to CostCentre with
CostCentre[Service=$interestingService] -- selecting only the
interesting CostCentre(s) -- before applying the other predicates.

Here's one flavor of that, applying minimal changes to your existing
code. Note that I'm taking advantage of the fact that you can apply more
than one predicate, just to keep this modular and easy to read; you
could of course combine this test into the existing select predicate
instead.

<xsl:variable name="interestingService"
select="'Directorate Management Team'"/>
<xsl:for-each
select="//CostCentre[Service=$interestingService][generate-id(.)=generate-id(key('AllServices',Service))]">
<xsl:sort select="ServiceOrder" data-type="number" />
<li><xsl:value-of select="Service" /></li>
<xsl:variable name="currentService">
<xsl:value-of select="Service"/>
</xsl:variable>
<ul>
<xsl:for-each
select="//CostCentre[Service=$interestingService][generate-id(.)=generate-id(key('AllServiceDivisions',concat(Service
';' ServiceDivisionName)))] ">
<xsl:sort select="ServiceDivisionOrder" data-type="number" />
<li><xsl:value-of select="ServiceDivisionName" /></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</ol>
Of course if you're only going to select one specific Service value,
there's no real need to include that value in your Muenchen keying...
but I'm trying to minimize changes to your existing code
Dec 7 '06 #2
On Dec 7, 2:30 am, Joe Kesselman <keshlam-nos...@comcast.netwrote:
It'd help if you'd been a bit more specific about how you wanted to
filter this. Since you said you want to filter based on $currentService,
and that's being set from the value of the <Serviceelement, I presume
your goal is to select only those <CostCentre>s which have a particular
<Servicevalue.
Hello Joe,

Sorry, looking back at my post today it is indeed not very clear what I
want. I suppose a more accurate description would be "Grouping" rather
than "Filtering", as that's what the filter is doing; I am creating a
report for an intranet which groups together cost centres in the
relevant areas; Section, Service Division and Service. The data is
exported from an Access database.

Many thanks for the reply; your solution worked perfectly, and slots
into my code to give me just what I need. Hopefully I can now use this
throughout the rest of the reports. Once again thanks for the clear and
concise reply.

Luke

Dec 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tristan Miller | last post by:
Greetings. I have a question involving sorting and grouping output using XSLT. I am trying to produce a publication list from a BibTeX-like XML file: <bibxml:file...
1
by: rayt | last post by:
I’m relatively new to XSLT and must admit I’m finding it refreshing, but every now and again something comes along which floors me. Maybe it’s the old imperative language background that is hard to...
3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
3
by: Prasad Karunakaran | last post by:
I have the following C# code to enumerate the list of groups in a domain using ADSI. The problem is if the domain contains machine accounts ($) it get those accounts too. Can somebody help me...
1
by: Jay | last post by:
I need to add a parameter to a directorysearcher.filter rather than using hard-coded text. I have the following code that finds all members of an AD group and then for each of those results tries...
1
by: mike | last post by:
Hi, I'm trying to apply Muenchian grouping to the XML displayed below but having no success, I'm trying to group on the section element, any pointers would be much appreciated: Thanks, Mike
1
by: lennyw | last post by:
Hi I'm trying to use XSLT to do an xml to xml transformation where the output xml contains summary data on the information in the input xml. I've succesfully done a Muenchian grouping of the...
1
by: aleksander.hansen | last post by:
Hello, I have xml data that I need to group and sort. I have tried grouping it using the Muenchian Method. Probably not solved the best way, but it works. But I can't get the sorting right. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.