Re: [xsl] Re: [xslt transform & grouping] Using the Muenchian Method?

Subject: Re: [xsl] Re: [xslt transform & grouping] Using the Muenchian Method?
From: Anton Triest <anton@xxxxxxxx>
Date: Thu, 07 Oct 2004 15:09:58 +0200
Michael PG wrote:

Now when everything else is working, and when I found the workaround to use Muenchian method in MSXML, I have one more issue.

Currently, when grouping is performed, (see the structure of the XML below), if there is no attribute filter defined in Article element (see info=child in the third Document parent node), or if there is no value in the Article element, the group "child" will not be generated, instead the Article element will hang outside it's own group or directly in the root.

I would like not to display all other elements (like the one in the XML examle below) that doesn't contain any value in the filter element, att all in the tree root.

In the XPath, you can add a predicate to the Document element: [Article[@filter=$filter]]
That would leave out the Document elements with no Article passing the filter.
But I noticed something else... the Document[@filter='' or @filter=$filter] predicate seems to have no effect.
This has been a somewhat chaotic thread, and I'm not sure why it was introduced, in any case
if you remove that predicate, the output stays the same. If it was meant to completely filter out Document
elements with a different filter then it doesn't work: Article "2.2" is in the output although its parent has
a filter="drink". (I think it has no effect on the output because a key selects elements in the whole file).
If on the other hand it was meant to allow passing an empty string in the param (for not applying any filter)
then you need [$filter='' or @filter=$filter] instead of [@filter='' or @filter=$filter].


If you can't get it to work then it might be a good idea to start this all over again, and give us once more
a detailed description of what you want, for all possible combinations of filters, with a sample input and
above all, the desired output.


Anton



Thanx,


-Mike

In the following XSLT (current state)

<?xml version='1.0' encoding='UTF-8'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:key name="by-info" match="Article" use="@info"/>

<xsl:param name="filter" select="'food'"/>


<xsl:template match="Documents">
<Documents>
<xsl:for-each select="Document[@filter='' or @filter=$filter]/Article[generate-id()=generate-id(key('by-info',@info)[@filter='' or @filter=$filter])]">
<Document name="{@info}">
<xsl:copy-of select="key('by-info',@info)[@filter=$filter]"/>
</Document>
</xsl:for-each>
</Documents>
</xsl:template>


</xsl:stylesheet>


XML



<?xml version="1.0" encoding="utf-8"?>


<Documents>
<Document chapter="1" title="title 1" href="file1.xml" filter="food">
<Article title="1.1" info="sub" filter="food"/>
<Article title="1.2" info="main" filter="food"/>
</Document>
<Document chapter="2" title="title 2" href="file2.xml" filter="drink">
<Article title="2.1" info="sub" filter="drink"/>
<Article title="2.2" info="main" filter="food"/>
</Document>
<Document chapter="3" title="title 3" href="file2.xml" filter="">
<Article title="3.1" info="sub" filter="drink"/>
<Article title="3.2" info="child" filter=""/>
</Document>
</Documents>



From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Re: [xslt transform & grouping] Using the Muenchian Method?
Date: Wed, 6 Oct 2004 13:44:00 +0100


> I tried to use other namespace in XSLT file.
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"/>

that's not just another namespace that is a different language that is
almost completely unrelated to XSLT. It was implemented in msxml 2 (and so
IE5) prior to Microsoft implementing XSLT, MSXML3 implemented both
languages, MSXML4 and later products only implement XSLT. No
non-microsft product ever implemented that language, which was loosely
based on an early draft of XSL but mainly consisted of microsoft specific
constructs.


Microsoft's wd-xsl doesn't have anything analogous to xsl:key as far as
I can recall and the behaviour of its templating language was quite
different. So you'd have to completely re-write your stylesheet to use
that language.

It would be bizarre indeed to use that language when it is not supported
in any current product. I don't know but I would be most surprised if it
is implemented in the standard .net classes.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Current Thread