Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse XSL output

Tags:

xml

xslt

I have an XSL and its XML output. Can I produce a sample input file using these? I need to see how the structure of the input XML needs to be.

like image 490
Michael Avatar asked Oct 14 '22 19:10

Michael


2 Answers

I have an XSL and its XML output. Can I produce a sample input file using these?

For any function f()to have a reverse, it is necessary that the f() is a bidirectional 1:1 mapping.

Not all functions are bidirectional 1:1 mappings. The simplest example that comes to mind is:

f(x) = x^2

So squaring isn't a bidirectional 1:1 mapping. Applying the reverse of squaring to 9 would have to produce two values -- -3 and 3, but by definition a function can produce only a single value.

Generally, if a function isn't a bidirectional 1:1 mapping, it is lossy, and not all information it has on input is present in (or can be deducted from) the result.

In the case of squaring the information that is lost is whether the argument was positive or negative.

There are functions that lose 100% everything, like the constants:

f(x) = 1

Typically an XSLT transformation is a function that transforms the source XML document to some output result. Generally such transformation is lossy (for example we often are told to discard/ignore some attributes or elements).

Thus the answer whether the input to a transformation can be recovered from the output is generally negative.

Even if not the exact input, but "a sample input" is necessary, this cannot always be produced and it will never contain the data that is lost by the transformation.

like image 81
Dimitre Novatchev Avatar answered Oct 24 '22 22:10

Dimitre Novatchev


You might get an idea of some of the original format, however it is likely that you will not be able to reconstruct the complete original.

If the XSLT does not use part of the original XML in order to construct the output, you can't reconstruct the original structure.

Additionally, if your XSLT is using templates correctly, it may be difficult to discern which templates were called when (and in particular how the original XML was processed).

like image 23
Oded Avatar answered Oct 25 '22 00:10

Oded