A couple of changes to a solution I posted a few days ago should give
you exactly what you want...
This XSL >>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="sourceDoc" select="document('file_1.xml')"/>
<xsl:variable name="translationDoc" select="document('file_2.xml')"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="groupTranslation">
<xsl:element name="translations">
<xsl:apply-templates select="$sourceDoc/file1/terms">
<xsl:with-param name="translationDoc"
select="$translationDoc/file2/translated"/>
</xsl:apply-templates>
</xsl:element>
</xsl:variable>
<xsl:copy-of select="$groupTranslation"/>
</xsl:template>
<xsl:template match="terms">
<xsl:param name="translationDoc"/>
<xsl:variable name="pos" select="position()"/>
<xsl:element name="tranlatedTerm">
<xsl:element name="source">
<xsl:attribute name="lang"><xsl:value-of
select="source[position() = 1]/@lang"/></xsl:attribute>
<xsl:value-of select="source[position() = 1]/term"/>
</xsl:element>
<xsl:element name="translation">
<xsl:attribute name="lang"><xsl:value-of
select="$translationDoc/term[position() = $pos]/@lang"/></xsl:attribute>
<xsl:value-of select="$translationDoc/term[position() = $pos]"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Outputs this XML >>
<?xml version="1.0" encoding="UTF-8"?>
<translations>
<tranlatedTerm>
<source lang="english">dog</source>
<translation lang="danish">hund</translation>
</tranlatedTerm>
<tranlatedTerm>
<source lang="english">dog</source>
<translation lang="danish">bord</translation>
</tranlatedTerm>
</translations>
Now just convert the $groupTranslation variable to a nodeset and you can
use apply-templates to transform it or just store it as is as an XML
file for later use.
Best of luck!
<M:D/>
-----Original Message-----
From: ronan martin [mailto:ronanmartin124(_at_)hotmail(_dot_)com]
Sent: Thursday, March 25, 2004 4:46 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] replacing values in file1 from file2
Hi
I've been stuck on this - I thought it would be simpler than it is. (I'm
pretty much only just past beginner level)
I have two xml files. One with pairs of terms in source and target
language
but with an untranslated target language term (say, English and Danish).
In
another xml file I have the Danish translations, one for each pair of
terms,
and sequenced in exactly the same way.
<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
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.
Sorry this is so long-winded. I simplified the xml. In reality I'm using
tmx
which is a translation memory format.
thanks
Ronan
_________________________________________________________________
Få alle de nye og sjove ikoner med MSN Messenger http://messenger.msn.dk
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
You are subscribed as: m(_dot_)david(_at_)mdptws(_dot_)com
To unsubscribe, go to:
http://lists.mulberrytech.com/unsub.php/xsl-list/m(_dot_)david(_at_)mdptws(_dot_)com
or e-mail:
<mailto:xsl-list-unsubscribe-m(_dot_)david=mdptws(_dot_)com(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--