Subject: Re: Ignore Tags
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Tue, 26 Feb 2002 21:00:31 +0100
|
This is a general grouping problem.
The easiest way is to test (with the preceding-sibling-axis) whether there
was already a child with this id:
<xsl:template match="root">
<xsl:apply-templates select="child[not(@id =
preceding-sibling::child/@id)]"/>
</xsl:template>
<xsl:template match="child">
do anything with the happy childs
</xsl:template>
The second way for bigger files (the above way is not so good, because for
every child all preceding childs have to be tested) is using keys (Muenchian
Method, http://www.jenitennison.com/xslt/grouping/muenchian.html)
<xsl:key name="childs" match="child" use="@id"/>
<xsl:template match="root">
<xsl:apply-templates select="child[count( . | key('childs', @id)[1]) =
1]"/>
</xsl:template>
Hope this helps,
Joerg
> hi
>
> I have a problem .. it goes like this
> an xml file of thie folowing format
>
> <root>
> <child id = '1'>happy</child>
> <child id = '2'>happy</child>
> <child id = '3'>happy</child>
> <child id = '1'>sad</child>
> <child id = '2'>sad</child>
> <child id = '3'>sad</child>
> </root>
>
> my problem is that when i go through each of the child elements,
> then i should ignore the duplicates that is once child id = '1' is
> encountered, the second time it should be ignored.. so effectively
> the result should be
> all happy 'childs' .. Is there a way to do that??
> please help me
> vsd
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- Ignore Tags
- vasu deva - Tue, 26 Feb 2002 13:24:53 -0500 (EST)
- Joerg Heinicke - Tue, 26 Feb 2002 14:55:43 -0500 (EST) <=
- <Possible follow-ups>
- vasu deva - Tue, 26 Feb 2002 15:09:52 -0500 (EST)
|
|