Subject: RE: [xsl] replacing values in file1 from file2 From: "ronan martin" <ronanmartin124@xxxxxxxxxxx> Date: Mon, 29 Mar 2004 09:37:14 +0200 |
File1 <tmx version="1.4"> <body> <tu> <tuv xml:lang="en-us"> <seg> <ph x="1">key1=</ph> </seg> </tuv> <tuv xml:lang="da-dk"> <seg> <ph x="2">key1=</ph> </seg> </tuv> </tu> <tu> <tuv xml:lang="en-us"> <seg>"monday"</seg> </tuv> <tuv xml:lang="da-dk"> <seg>"monday"</seg> </tuv> </tu> <tu> <tuv xml:lang="en-us"> <seg> <ph x="1">key1=</ph> </seg> </tuv> <tuv xml:lang="da-dk"> <seg> <ph x="2">key1=</ph> </seg> </tuv> </tu> <tu> <tuv xml:lang="en-us"> <seg>"tuesday"</seg> </tuv> <tuv xml:lang="da-dk"> <seg>"tuesday"</seg> </tuv> </tu> </body> </tmx>
File2 <values> <value>mandag</value> <value>tirsdag</value> </values>
From: <Jarno.Elovirta@xxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: RE: [xsl] replacing values in file1 from file2 Date: Thu, 25 Mar 2004 14:24:39 +0200
Hi,
> <file1> > <terms> > <source lang="english"> > <term>dog</term> > </source> > <source lang="danish"> > <term>dog</term> > </source> > </terms> > <terms> > <source lang="english"> > <term>dog</term> > </source> > <source lang="danish"> > <term>dog</term> > </source> > </terms> > </file1> > > <file2> > <tranlated> > <term lang="danish">hund</term> > <term lang="danish">bord</term> > </translated> > </file2> > > I've tried matching a nodeset in file1 using <.. > match="//source[@lang='danish']/term"> seems fine. Then I've tried to
With match patterns the leading // is not needed, just use
<xsl:template match="source[@lang='danish']/term">
> copy-of the value from select="document('file2.xml')//term/text()" in > various ways. I get the first value only from the list > copied, but in all > the locations I wanted. How do I pass on the number of the > node in the first > nodeset to the nodeset selected from the second file. I tried > setting up a > variable using position() but couldn't get it to work.
If you've simplified your source, then I suppose you can't change the source to use proper keys, instead of relying on the position for a match. First you want to know your position in file1
<xsl:variable name="position" select="count(../../preceding-sibling::terms)"/>
Then get the translated term
<xsl:value-of select="document('file2.xml')//term[count(preceding-sibling::term) = $position]"/>
For performance you want to replace the // walking with file2/translated, and also you might want to consider using keys: just use the preceding term sibling count as the key.
Cheers,
Jarno - Melotron: Manchmal
_________________________________________________________________ Fe alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] replacing values in file1, Jarno.Elovirta | Thread | RE: [xsl] replacing values in file1, Jarno.Elovirta |
RE: [xsl] Selecting all siblings an, Jarno.Elovirta | Date | RE: [xsl] replacing values in file1, Jarno.Elovirta |
Month |