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!

Old XML files translated, need changes applied to current... 2

Status
Not open for further replies.

miglaugh

Technical User
Dec 7, 2006
5
US
Hey Guys,

Our software package is in the midst of a localization effort. A pull of all the relevant files was taken about 6 months ago and translations of all the key fields were done. I've managed to get every area in sync and automated except for the XML files.

What I have are 6 month old files with bits here and there translated, mostly around "caption" and various other text elements. Since 6 months have passed, the current files have gone through various changes, some gaining data, some losing data. I need to map the translated text from the old files to the current files, without breaking the current files.

What I'm looking for is a tool that I can use to update the current files using the old translated ones as a guide. For example I'd like to give a file as a master, where no data can be removed or added, only changed. Then take the translated file and map it's changes onto the current file, but only the relevant changes (ex. translated text, not functional changes.)

I've found some tools that can compared two XML files and record the changes to another file, but I can't seem to get the results the way I want.

The only alternative is to cut and paste, and that is a nightmare, considering revisions of the translated files are sure to come again and again...

Any ideas jump into peoples heads about this?

Thanks,
Brian
 
I guess by the silence there is no dream automation tool for this kind of thing...

I was able to find a program called Altova DiffDog that made this task much easier than it would've been otherwise. With that tool, it targets the changes based on element/attribute, not one line at a time like most other compare tools. With quick eyes and fingers I was able to compare/edit/save a file in under a minute... not nearly as bad as copy/paste(god forbid) would've been.

Later.
 
Brian,

Glad you found that tool. Was totally unaware of it, but it sounds like it did the job well.

I would have suggested a template driven XSLT, but that would have been quite a bit of work, especially if you are not familiar with XSLT.

A star for coming back with a good result and answer. We appreciate the followup!

Tom Morrison
 
Hey Tom,

Thanks for the tip.

So I can avoid the initial google stumbling, do you have a site in mind with good information on XSLT? I'd still be interested in automating this task, as I may be called upon at a later date to perform it again.

Is a good place to start?

Ideally I'd just like some sample files to reverse engineer, but as long as I have a solid starting point I'll be good.

Any pointers?

Brian
 
Brian,

Yes w3schools is a good starting spot. I rely heavily on a couple books as well:[ul square][li]XSLT, Doug Tidwell, O'Reilly & Associates[/li][li]XSLT Programmer's Reference, Michael Kay, Wrox[/li][li]Inside XSLT, Steven Holzner, New Riders[/li][/ul]

The Stylus Studio product helps, as does Altova. My personal preference is Stylus Studio, my boss loves Altova. Stylus has lots of examples. Both Stylus and Altova offer a free trial period.

Tom Morrison
 
Brian,

As for automating the task, you should have a look at recursion XSLT style as a means of working your way through a template document to discover changes in the document under inspection.

Key learning points are (as stated) recursion, XPath expressions, and using the document() function effectively. XSLT (Tidwell) has an entire chapter devoted to the use of the document() function. There are some decent recursion examples here.

And, of course, coming back to Tek-Tips to help work through problems has been useful for some!

Tom Morrison
 
Thanks for the specific direction to look in... Just reading through the tutorials I was starting to get a little overwhelmed by how broad a range of implementation there is.

As usual I'm trying to do a simple task with something designed to rule the world (so to speak).

If I have any specific technical questions I'll be sure to return.

Bye for now,

Brian
 
Brian,

You can find, courtesy XSLT, a stylesheet that recursively traverses all elements of the input XML document here.

Inside the recursive routine, attributes are processed using an xsl:for-each processing instruction. So this stylesheet has everything you need to go through a template document.

I have modified the stylesheet to generate an XPath expression as it goes as follows.
Code:
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
  <xsl:output method="text"/>
  <xsl:variable name="nl">
<xsl:text>
</xsl:text>
  </xsl:variable>

  <xsl:template match="/">
  <xsl:for-each select="*">
	  <xsl:call-template select="." name="showElements">
	  	<xsl:with-param name="xpathOfElement" select="concat('/', name(), '[', position(), ']')"/>
	  </xsl:call-template>
  </xsl:for-each>
  </xsl:template>

  <xsl:template match="*" name="showElements">
  	<xsl:param name="xpathOfElement"/>
    <xsl:variable name="myName" select="name(.)"/>

	<xsl:text>I am in element </xsl:text>
	<xsl:value-of select="concat($myName,$nl)"/>
	<xsl:text>     My XPath is: </xsl:text><xsl:value-of select="concat($xpathOfElement,$nl)"/>
    <xsl:text>     My value is: </xsl:text><xsl:value-of select="concat(.,$nl)"/>
    <xsl:for-each select="@*">
	    <xsl:text>     I am in attribute </xsl:text><xsl:value-of select="concat(name(.),$nl)"/>
        <xsl:text>          My XPath is: </xsl:text><xsl:value-of select="concat($xpathOfElement,'/@',name(.))"/><xsl:value-of select="$nl"/>
        <xsl:text>          My value is: </xsl:text><xsl:value-of select="."/><xsl:value-of select="$nl"/>
    </xsl:for-each>
	<xsl:for-each select="*">
	    <xsl:call-template select="." name="showElements">
	 		<xsl:with-param name="xpathOfElement" select="concat($xpathOfElement,'/',name(),'[',position(),']')"/>
	    </xsl:call-template>
	</xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Run against this input XML document.
Code:
<?xml version="1.0"?>
<fields>
 <field id="1"><xpath>data/extradata/field2</xpath></field>
 <field id="22"><xpath>data/field1</xpath></field>
 <field id="11"><xpath>data/extradata/field1</xpath></field>
</fields>

Produces this output:
Code:
I am in element fields
     My XPath is: /fields[1]
     My value is: 
 data/extradata/field2
 data/field1
 data/extradata/field1

I am in element field
     My XPath is: /fields[1]/field[1]
     My value is: data/extradata/field2
     I am in attribute id
          My XPath is: /fields[1]/field[1]/@id
          My value is: 1
I am in element xpath
     My XPath is: /fields[1]/field[1]/xpath[1]
     My value is: data/extradata/field2
I am in element field
     My XPath is: /fields[1]/field[2]
     My value is: data/field1
     I am in attribute id
          My XPath is: /fields[1]/field[2]/@id
          My value is: 22
I am in element xpath
     My XPath is: /fields[1]/field[2]/xpath[1]
     My value is: data/field1
I am in element field
     My XPath is: /fields[1]/field[3]
     My value is: data/extradata/field1
     I am in attribute id
          My XPath is: /fields[1]/field[3]/@id
          My value is: 11
I am in element xpath
     My XPath is: /fields[1]/field[3]/xpath[1]
     My value is: data/extradata/field1

This should give you a jumpstart into the problem of using this example to traverse your input template document and then use the document() function to investigate the identical spot in the document under test.

Welcome to XSLT!

Tom Morrison
 
Hey Again,

After digging around on the net for a while, trying to figure out the best approach for this project, I started thinking that learning all of this XSLT stuff wasn't worth the effort. At least not right now. It just seems far too complex for what I need it to do.

I'd love to have the time to learn all that stuff from the ground up and be able to put it on the ol' resume, but I'll need a project better suited to the power of XSLT to pull me to it.

Anyways, what I've settled on is writing a VB6 program using the Chilkat XML API. I write excel macros all the time so the syntax will hide no secrets, and maybe entering the XML world through an API will help the XML specific stuff to "click" better. The XSLT stuff just wasn't clicking (perhaps because I was trying the ol' square peg/round hole mantra). Either way it's too hard to see through all the syntax and get at what the actual function is or how to wield it.

With API functions like:
SearchForAttribute
GetAttributeName
GetAttrValue
and many others, Chilkat gives me the option to focus on my algorithm instead of worrying about the syntax and various other issues.

Thanks for the advice, as I wouldn't have come to this conclusion without taking the path I did. And who knows, maybe this will spark the hunger to learn whats underneath the API.

Later,

Brian
 
Brian,

Different people learn in different ways. I have had a look at the API you linked, and while it seems to have the same level of complexity as XSLT, the API approach does offer a different way to frame a solution.

Anyway, welcome to Tek-Tips, and be sure to come back to the XML Forum.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top