This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: document() merge DISTINCT
- From: "Alex Schuetz" <asc at ala dot de>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 19 Dec 2001 13:34:50 +0100
- Subject: Re: [xsl] document() merge DISTINCT
- Organization: SSH
- References: <010801c18880$84f191e0$2100a8c0@swiftnet.tec>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hallo Chris,
it does not work for me as expected..
I guess, I do not understand the meaning on current() in this context:
To make it simpler for me, say I have more then two files I want to merge
as:
sample.xml:
<p>
<person name="name2" id="2"/>
<person name="name3" id="8"/>
<person name="name4" id="32"/>
</p>
In each file all /person/@id are unique, but different files might contain
the same @id .
Now I want to produce a list of all <person> so that /person/@id is unique.
As you suggested, I tried:
<xsl:template match="person">
<xsl:copy>
<xsl:copy-of
select="document($file)/p/person[not(@id = current()/p/person/@id]"/>
</xsl:copy>
</xsl:template>
It looks to me, that [not(@id = current()/p/person/@id] is always true and I
get a list with non unique <person>.
-Alex
----- Original Message -----
From: "Chris Bayes" <chris@Bayes.co.uk>
To: <xsl-list@lists.mulberrytech.com>
Sent: Wednesday, December 19, 2001 12:30 PM
Subject: RE: [xsl] document() merge DISTINCT
> Alex,
> Something like this should do it
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:param name="file" />
> <xsl:template match="/">
> <xsl:apply-templates select="/p/project" />
> <xsl:copy-of select="document($file)/p/project[not(@name
> = current()/p/project/@name)]" />
> </xsl:template>
> <xsl:template match="project">
> <xsl:copy>
> <xsl:copy-of select="@*|*" />
> <xsl:copy-of
> select="document($file)/p/project[@name =
> current()/@name]/person[not(@id = current()/person/@id)]" />
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
> Ciao Chris
>
> XML/XSL Portal
> http://www.bayes.co.uk/xml
>
>
> > -----Original Message-----
> > From: owner-xsl-list@lists.mulberrytech.com
> > [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> > Alex Schuetz
> > Sent: 19 December 2001 09:31
> > To: XSL-List@lists.mulberrytech.com
> > Subject: [xsl] document() merge DISTINCT
> >
> >
> > Hallo;
> >
> > I have some input files with the /person/@id attribute being
> > unique in each file (and /project).
> >
> > input.xml
> > --------------------------------------------------------------
> > <project name="some-name">
> > <person id="1" name="name1"/>
> > <person id="5" name="other-name"/>
> > <preson id="20" name ="another-name"/>
> > </project>
> > ------------------------------------------------
> >
> > I want to merge these files so that I get a list of all
> > <person> that are in any <project> but the preson/@id should
> > be unique, that is, no <person> element should be listed twice.
> >
> > In the book 'XSLT' from Dough Tidwell (chapter 7) there is an
> > example that works but is using a lot of disk reads and deep
> > recursion. It goes like this:
> >
> > 1: build a variable var1 as a white-space separated sorted
> > list of all @id . (using <xsl:for-each select="document(...)"..../> )
> > 2: build a variable var2 of unique @id from var1 (by recursion);
> > 3: with var2 call a template that calls <xsl:for-each
> > select= "document(....)"../> for each id in var2 and produces
> > the output.
> >
> > Is there a better way to do this?
> >
> > -Alex
> > asc@ala.de
> >
> >
> >
> >
> > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> >
> >
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list