views:

235

answers:

1

I need to maintain some old XSL code and I've discovered that there's a lot of duplication in the XSL files. It looks like there isn't an easy include/import function for XSL which would allow me to move the code to a different file and just include it when needed.

This sounds like it could be done with Model Driven Development tools but I've only heard about it, not actually used it and it is probably overkill for the job.

Is there a simple preprocessor that can be called from Ant which has include/import support?

A: 

There is an include mechanism for XSL. See http://www.w3.org/TR/xslt#section-Combining-Stylesheets for details.

If you can't achieve what you want with that, you can preprocess your XSL with another XSL transform: XSL is just XML. But... I don't think that the programmers who have to maintain your project after you've gone will thank you for doing that!

If you just want a cross-platform replacement for M4 you can invoke Velocity, Freemarker or another template library from Ant.

Nat
I tried to use that, but it's not very straight-forward. I believe I would have to insert a tag in the XML, then tie the included XSL to the new tag. That wouldn't be so bad, but unfortunately we're extending a proprietary system which is generating the XML so I can't actually modify the XML being output.
sjbotha
To use XSL's include mechanism can just add an <xsl:import ...> or <xsl:include ...> element to your XSL stylesheet. You don't need to change the XML being transformed.To transform XSL itself you can just add elements to the source XSL that are defined in your own namespace and have another transform turn those elements into plain XSL.
Nat