xsl-list
[Top] [All Lists]

RE: replacing values in file1 from file2

2004-03-29 00:37:14
Jarno - thanks for the suggestion.

I've worked away at it, but I'm still running into the same problem. Could be the variable is going out of scope in some way. Here is the actual xml that I'm working with (minus some attributes and irrelavant children). First File1, then File2, and then the template I'm trying to use. There are two terms, Monday and Tuesday, which are to be translated. My limitation is that I can't change the structure or add elements as this has to be fed back into an application.

thanks Ronan

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>

Transate.xsl
<xsl:template match="tuv[(_at_)xml:lang='da-dk']/seg[not(child::ph)]/text()">
 <xsl:variable name="position" select="count(preceding-sibling::self)"/>
 <xsl:for-each select=".">
<xsl:value-of select="document('File2.xml')//value[count(preceding-sibling::value) = $position]"/>
 </xsl:for-each>
</xsl:template>

From: <Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
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[(_at_)lang='danish']/term"> seems fine. Then I've tried to

With match patterns the leading // is not needed, just use

  <xsl:template match="source[(_at_)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

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
You are subscribed as: ronanmartin124(_at_)hotmail(_dot_)com
To unsubscribe, go to: http://lists.mulberrytech.com/unsub.php/xsl-list/ronanmartin124(_at_)hotmail(_dot_)com or e-mail: <mailto:xsl-list-unsubscribe-ronanmartin124=hotmail(_dot_)com(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


_________________________________________________________________
Få alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk



<Prev in Thread] Current Thread [Next in Thread>