3

I need this for patching. I can't change the first xml, but I have the possibility to apply .xslt to create patched version from original file.

Which commands I should use?

Also, which command will create the second .xml from first xml and xslt ?

i.e. I want something like MS XMLDiffPatch (~year 2002), but with XSLT instead of Diffgram (Xml Diff Language).

I expected that such work is already done for XSLT. Because for RFC5261 (https://www.rfc-editor.org/rfc/rfc5261) it was done in 2012 (3 years ago) - http://github.com/Bonuspunkt/XmlPatch
Any version of XSLT is suitable (i.e. 2.0, 3.0).

Some theoretical works in this field:

Linked questions:

7
  • 1
    Too board. You have to define the schema of the first and second file, then write the XSLT to do the transformation. And there's no way to "restore" the second file back to the first. You will have to write another XSLT for the task. Commented Sep 18, 2015 at 16:15
  • I don't need to transform second file back to the first. I want an utility which will create .xslt for direct transform from first to second only. Commented Sep 18, 2015 at 16:16
  • @ZoffDino, there may exist such a thing as lossless transformation, in which case restoration is possible, but indeed, will require another XSLT to do it. Commented Sep 18, 2015 at 16:48
  • Take a look at the DeltaXML product. Commented Sep 19, 2015 at 14:09
  • 1
    Dear @user1709408 , Abel's answer is correct, but maybe if you are looking for some interesting algorithm, for example to minimize the changes or similar, then cs.stackexchange.com waits you. Commented Sep 19, 2015 at 16:08

1 Answer 1

4

If I have 2 .xml files, how to create .xslt which will transform first file into second file?

This can be done with:

<!-- two XML files -->
<xsl:param name="file1" select="'file1.xml'" />
<xsl:param name="file2" select="'file2.xml'" />

<!-- call with -it main on commandline, will transform file1 into file2 -->
<xsl:template name="main">
    <xsl:result-document href="{$file2}" >
        <xsl:copy-of select="document($file1)" />
    </xsl:result-document>
</xsl:template>

Use xsl:apply-templates and a copy idiom if you need to do some transformation on the first into the second file.

Be aware that the you cannot read and write to the same file. So if you want to also read from file2.xml then you should use a different URI for writing.

Which commands I should use? Any version of XSLT is suitable (i.e. 2.0, 3.0).

On the tag's info page there's a listing of a myriad of processors that support from XSLT 1.0 to 3.0. You can choose whichever one you like, though the above example will work with XSLT 2.0 and up only.

Sign up to request clarification or add additional context in comments.

9 Comments

it doesn't transform first file into second one, because it doesn't contain differences inside .xslt. It just perform raw copying.
I can choose any processor to apply .xslt (which is second step).
@user1709408, yes, so it transforms the first file into second file. Without any requirements, that's the only thing I could make understand from your question. But, as a hint, I just updated the question and suggested to use xsl:apply-templates, the rest is the same.
But I want an utility which records differences into .xslt automatically (like diff)
@user1709408, slowly you are getting closer to what you actually want. Why don't you rewrite your question so that it explains what you actually want? I don't know about expectations, but implementation of a standard relies on people needing it. If there was no need, then nobody builds it. But feel free to do so. I may be wrong, perhaps it exists, but I haven't heard of it.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.