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

Subject: Re: [xsl] Re: [xslt transform & grouping] Using the Muenchian Method?
From: "Michael PG" <xrow@xxxxxxx>
Date: Wed, 06 Oct 2004 07:25:42 +0000
Hi Anton,


Here's the XSL stylesheet:


<?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:param>

<xsl:template match="Documents">

<!-- @filter='' will be true if it is there and empty or if it is not there at all) -->
<xsl:apply-templates select="*[@filter='' or @filter=$filter]"/>


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


</xsl:template>

</xsl:stylesheet>


The line proposed by David C. gives an exception.


<xsl:for-each select="Document[@filter='' or @filter=$filter]/Article[count(.|key('by-info',@info)[@filter='' or @filter=$filter][1])=1]">


The XML looks like:


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

<Documents>
	<Document chapter="1" title="title 1" href="file1.xml" filter="">
		<Article title="1.1" info="sub" filter="drink"/>
		<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>
</Documents>


Thanx.


-M


From: Anton Triest <anton@xxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Re: [xslt transform & grouping] Using the Muenchian Method?
Date: Wed, 06 Oct 2004 00:47:56 +0200


Michael PG wrote:

After adding the suggested line I got an exception lake it last case.

select="Document[@filter='' or @filter=$filter]/Article[count(.|key('by-info',@info)[@filter='' or @filter=$filter][1])=1]">


Hi Michael (I'm jumping in again, was away yesterday)

did you define the key in this template? (that caused the exception last time, didn't it)
if so, maybe you'll better post the complete stylesheet once more... (+ exception details)


Anton


_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement


Current Thread