Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XLIFF populate nodes - Advice needed

Status
Not open for further replies.

MakeItSo

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

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top