Re: [xsl] determining node position by the content of a text node

Subject: Re: [xsl] determining node position by the content of a text node
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 12 Sep 2005 13:54:31 +0200
Hi,

Tempore 13:33:34, die 09/12/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Thomas Winkler <thomasm003@xxxxxxxx>:

Find a text-node named "Kunde". Then call the
dictionary and search for that word.After finding it,
remember the position of that word, because the
english text node for that German word is one
element-node before.

That's a very fragile algorithm. What garanty is there that the English translation is exactly before the German version?


If you'd like to persist with this technique, then at least store the node itself, instead of its position (it's not easy to calculate the position within xpath).

<xsl:variable name="Germanword" select="document('dict.xml')//seg[text()=$trans]"/>
<xsl:variable name="Englishword" select="$Germanword/preceding::seg[1]"/>


In my opinion, it's far better to use keys instead.


e.g. <xsl:key name="term" match="wort" use="concat(@xml:lang,'-',seg)"/>

<xsl:variable name="Englishword">
	<xsl:for-each select="document('dict.xml')">
		<xsl:value-of select="key('term',concat('de-',$trans))/../wort[@xml:lang='en']"/>
	</xsl:for-each>
</xsl:variable>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Laudeo W3C et dona ferens

Current Thread