[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: <Jarno.Elovirta@xxxxxxxxx>
Date: Thu, 25 Mar 2004 14:24:39 +0200
xsl replacing values
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

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.