INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XLIFF populate nodes - Advice needed

XLIFF populate nodes - Advice needed

(OP)
Hello friends,

I do not yet have any code for the following. I first need advice on how to do this at all first.
Problem: I have an XML file, XLIFF to be precise.
<source> nodes contain text, <target /> nodes are empty.
These files need to be translated using a CAT (=translation) tool. Said CAT tool however needs the target nodes containing the source text beforehand.
How would I best do that? The depth of the tree hierarchy is unknown!
Here's a sample XLIFF:

CODE

<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:tek="http://www.tektronix.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2
xliff-core-1.2-strict.xsd http://www.tektronix.com tek_code_trial.xsd" version="1.2">
<tek:header>The First Volume of Software Structures</tek:header>
<file original="String" source-language="en-us" datatype="plaintext">
<header>
<skl>
<internal-file form="String" crc="NMTOKEN">String</internal-file>
</skl>
<phase-group>
<phase phase-name="String" process-name="String" company-name="String">
<note xml:lang="en-us" priority="1" from="String">String</note>
<note xml:lang="en-us" priority="1" from="String">String</note>
</phase>
<phase phase-name="NMTOKEN" process-name="String" company-name="String">
<note xml:lang="en-us" priority="1" from="String">String</note>
<note xml:lang="en-us" priority="1" from="String">String</note>
</phase>
</phase-group>
<glossary>
<internal-file form="String" crc="NMTOKEN">String</internal-file>
</glossary>
<glossary>
<internal-file form="String" crc="NMTOKEN">String</internal-file>
</glossary>
</header>
<body>
<trans-unit id="_1_ski_041" approved="yes" translate="yes" reformat="coord font" xml:space="default">
<source xml:lang="en-us">Text <g id="_1_ski_040">text</g>TEXT<bpt id="_1_ski_139">code</bpt></source>
<target state="needs-translation" xml:lang="de-de" resname="String" />
<context-group name="_ski_40119" crc="NMTOKEN" purpose="location x-test match x-abcdef">
<context context-type="database" match-mandatory="no" crc="NMTOKEN">String</context>
<context context-type="database" match-mandatory="no" crc="NMTOKEN">String</context>
</context-group>
<count-group name="_ski_42117">
<count count-type="new" phase-name="String" unit="word">String</count>
<count count-type="new" phase-name="String" unit="word">String</count>
</count-group>
<note xml:lang="en-us" priority="1" from="String">String</note>
<note xml:lang="en-us" priority="1" from="String">String</note>
<alt-trans match-quality="String" crc="NMTOKEN">
<source xml:lang="en-us">Text</source>
<target state="needs-translation">Text</target>
</alt-trans>
</trans-unit>
<trans-unit id="_1_ski_2203">
<source><mrk mtype="protected">XLIFF</mrk>stands for<mrk mtype="protected">XML Localisation Interchange File Format</mrk>.</source>
<target />
</trans-unit>
<group id="_1_ski_2318" datatype="plaintext"></group>
<group id="_1_ski_2516" datatype="plaintext">
<group id="test.indd">
<group id="Paragraph1">
<note xml:lang="en-us" priority="1" from="String">String</note>
<trans-unit id="_1_ski_2515">
<source xml:lang="en">Text</source>
<target xml:lang="de"/>
</trans-unit>
</group>
</group>
</group>
<bin-unit id="_1_ski_2714" mime-type="image">
<bin-source>
<internal-file form="String" crc="NMTOKEN">String</internal-file>
</bin-source>
<bin-target mime-type="image" state="needs-translation" phase-name="NMTOKEN" restype="button" resname="String">
<internal-file form="String" crc="NMTOKEN">String</internal-file>
</bin-target>
</bin-unit>
</body>
</file>
</xliff>

The bold black parts are what I need: node "trans-unit", populate the target node with the entire contents of the source node.
Notice the red part: there may also exist "alt-trans" nodes - these are to be left as is.
Notice the purple bold part: the trans-unit nodes with the source/target nodes may also be buried under any amount of "group" nodes.

So I need a way to populate the relevant target nodes (without exactly knowing how deep they're buried) while leaving the entire rest of the file as is.

Question: is such a thing possible using XSL(T)? If so: can you give me any pointers/directions as to how the transformation must look like?
Or would this be rather a job for some Script using recursion?
ponder

Thanks!
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close