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="*[(_at_)filter='' or
@filter=$filter]"/>
<Documents>
<xsl:for-each select="Document[(_at_)filter='' or
@filter=$filter]/Article[count(.|key('by-info',@info)[(_at_)filter='' or
@filter=$filter][1])=1]">
<Document name="{(_at_)info}">
<xsl:copy-of
select="key('by-info',@info)[(_at_)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[(_at_)filter='' or
@filter=$filter]/Article[count(.|key('by-info',@info)[(_at_)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(_at_)cking(_dot_)be>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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[(_at_)filter='' or
@filter=$filter]/Article[count(.|key('by-info',@info)[(_at_)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
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--
_________________________________________________________________
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