[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Merging attribute values to unique list
Subject: RE: [xsl] Merging attribute values to unique list From: Américo Albuquerque <melinor@xxxxxxx> Date: Sat, 2 Aug 2003 01:50:21 +0100 |
Hi > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > James Cummings > Sent: Friday, August 01, 2003 12:17 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Merging attribute values to unique list > > > > Hi there, > > This is similar to something I asked months ago, and you'd > think I'd be able to figure it out but... assuming you have a > file like> > > > <foo id="a1"> > <body wit="A B E D">some stuff</body> > <body wit="C A G">some other stuff</body> > </foo> > > What I want to produce is a list of links one for each unique > witness, so in this case something like: > > <p>See the reading for: > <a href="foo/a1.xml?wit="A">A</a> > <a href="foo/a1.xml?wit="B">B</a> > <a href="foo/a1.xml?wit="C">C</a> > <a href="foo/a1.xml?wit="D">D</a> > <a href="foo/a1.xml?wit="E">E</a> > <a href="foo/a1.xml?wit="G">G</a> > </p> > > So, I'm assuming what needs to happen is that I need to > somehow produce a list of each of the tokenized contents of > //body/@wit which are then sorted and made unique. Any > suggestions on how to go about this using Xalan inside > cocoon-2.1? I.e. I have some ideas on how to do it with > saxon extensions/xslt 2.0, but not inside cocoon. Any > suggestions appreciated! > > Try this, in saxon or xalan you can define fn to "http://exslt.org/common": <xsl:key match="wit" name="wits" use="@name"/> <xsl:template match="foo"> <xsl:variable name="wits"> <root> <xsl:apply-templates mode="wits"/> </root> </xsl:variable> <xsl:apply-templates select="fn:node-set($wits)"/> </xsl:template> <xsl:template match="root"> <p> <xsl:text>See the reading for: </xsl:text> <xsl:apply-templates select="wit[generate-id()=generate-id(key('wits',@name))]"> <xsl:sort select="@name"/> </xsl:apply-templates> </p> </xsl:template> <xsl:template match="wit"> <a href="foo/a1.xml?wit={@name}"> <xsl:value-of select="@name"/> </a> <xsl:text> </xsl:text> </xsl:template> <xsl:template match="body" mode="wits"> <xsl:call-template name="wits"/> </xsl:template> <xsl:template name="wits"> <xsl:param name="str" select="@wit"/> <xsl:choose> <xsl:when test="contains($str,' ')"> <wit name="{substring-before($str,' ')}"/> <xsl:call-template name="wits"> <xsl:with-param name="str" select="substring-after($str,' ')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <wit name="{$str}"/> </xsl:otherwise> </xsl:choose> </xsl:template> Regards, Americo Albuquerque XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Merging attribute values to u, James Cummings | Thread | [xsl] Re: Merging attribute values , Dimitre Novatchev |
RE: [xsl] How to speed up parsing ?, Craig Kattner | Date | [xsl] Re: for-each, hemi |
Month |