Project

Profile

Help

Serializing a merged, compiled xsl transform in .Net

Added by Martin Smith over 10 years ago

Greetings,

I am working on a project were we are developing complex .XSL transforms. In order to make the code modular and maintainable, we are making effective use of xsl:include statements.

However, the final, production-ready transform needs to be stored in a database as an XML data type.

Consequently, we need a way to write out the merged transform as a single .xsl file.

We are working in the .Net environment, and have successfully compiled transforms using Saxon for .Net.

However, there does not appear to be a way to write the merged transform back out again.

Any suggestions would be greatly appreciated,

Martin


Replies (4)

Please register to reply

RE: Serializing a merged, compiled xsl transform in .Net - Added by O'Neil Delpratt over 10 years ago

Hi Martin,

I don't think that is directly possible to achieve from Saxon. However, one possibility would be to use Saxon's obfuscation feature, which creates a zip file of the stylesheet files (see: http://www.saxonica.com/documentation/using-xsl/packaged-xslt.html). Another way could be to serialise the compiled transform yourself from Java into a binary file or a zip file of the styelsheets.

Hope that helps?

Kind regards,

O'Neil

RE: Serializing a merged, compiled xsl transform in .Net - Added by O'Neil Delpratt over 10 years ago

You could also write a XSLT stylesheet to merge your multiple stylesheets from your project. This is probably the best option.

A similar problem is described in the following post on stackoverflow and answered by Mike Kay:

http://stackoverflow.com/questions/5871405/recursively-merging-multiple-xslt-stylesheets


...

  

...

"(In fact, merging in the xsl:includes can have some minor side-effects as well. It means that templates in the included module come under the influence of attributes such as exclude-result-prefixes in the xsl:stylesheet element of the main module, and loses any such attributes that were present in the included module.)"

kind regards,

O'Neil

RE: Serializing a merged, compiled xsl transform in .Net - Added by Martin Smith over 10 years ago

Thanks,

Writing an XSL transform that merges the stylesheet is ultimately the solution that I went with.

The idea of using a transform to transform a transform did not occur to me, but is an elegant solution to the problem,

Martin

RE: Serializing a merged, compiled xsl transform in .Net - Added by John Lumley over 10 years ago

Writing an XSL transform that merges the stylesheet is ultimately the solution that I went with.

The idea of using a transform to transform a transform did not occur to me, but is an elegant solution to the problem,

Apart from the issue of @exclude-result-prefixes@ outlined earlier by Mike/O'Neil, this will work well for @xsl:include@. But if you're using @xsl:import@ (and by implication @xsl:apply-imports@) then you have a much larger challenge, which for some cases can be statically achieved by imposing a hierarchical set of priorities on templates, but this isn't universal and is quite hard.

Using XSLT to modify XSLT is much less difficult than you might think and can have lots of applications in areas like source-destination tracing (attaching attributes which pass through 'good XML citizen' transforms) or even partial evaluation. I quite often find myself defining documents (e.g. HTML pages) with embedded XSLT fragments, which can be transformed into full XSLT 'programs' to generate appropriate documents very easily.

Don't be afraid to treat XSLT as just some other XML! @xsl:namespace-alias@ can help with the 'quoting problem'.

John

    (1-4/4)

    Please register to reply