Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying an xslt to be namespace agnostic

I have a XSLT I've created to handle a particular xml document. However, now namespaces are being introduced in some, but not all of our documents. I'd like to use the same XSLT for these documents, however I'm having trouble modifying my stylesheet to be namespace agnostic.

It's been suggested previously to modify my xpaths to *[local-name()="ElementName"], however considering we've already made a stylesheet, this is very labor intensive.

In addition, I am aware I can set the xpath-default-namespace to the particular namespace, but as mentioned earlier, I cannot simply set it to #all or a list of possible namespaces. I'm looking for a more effective solution and have the extension functions of the Saxon processor available to me. Any ideas? Thanks.

like image 480
Jon W Avatar asked Feb 03 '09 16:02

Jon W


1 Answers

Have you considered pre-processing your XML documents?

You could remove all namespaces (be aware of possible clashes) and then process it using the existing XSL transformation.

Such an approach would have the advantage that you don't have to modify your XSLT at all. It stays readable (the *[local-name()='frob'] looks so awful) and maintainable.

like image 151
Dirk Vollmar Avatar answered Sep 28 '22 20:09

Dirk Vollmar