[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: replacing values in file1 from file2

Subject: RE: replacing values in file1 from file2
From: "ronan martin" <ronanmartin124@xxxxxxxxxxx>
Date: Mon, 29 Mar 2004 09:37:14 +0200
ronan martin
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[@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.Elovirta@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.