Basically I want to have one xslt to become my 'base' xslt and want to link this into child xslt files.
Is this possible?
The aim is to reduce code duplication.
We will have many child xslt files for the various customers all with their own formatting and additional text etc and don't want to repeat the base code for each client xslt.
I know we can format based on the type of customer but this will make the xslt cluttered. Would ideally just like customer related code for each customer.
Is this not the way to do xslt? I am new to xslt!
<xsl:import href="library/utility-include.xsl" />
The href path is relative to the current xsl file. <xsl:import/>
documentation.
Remember that you must write your import lines as the first child element of <xsl:stylesheet>
or <xsl:transform>
. They cannot appear throughout your files.
As all other answers have specified, there are two XSLT instructions:
<xsl:import>
and
<xsl:include>
that were designed exactly to provide this capability.
It may be of interest to you that there are complete libraries of templates and functions that internally import other stylesheets of the library. The stylesheets of the library are intended to be imported in the user's XSLT stylesheets.
For example, do have a look at the FXSL library for functional programming in XSLT.
All other answers give you sufficient information,
I want to mention one more important thing here .. You can even "pass the (in both ways) parameters" between the two (calling and called file, if they need to share any data) xslt files ..
This feature Plays important role in/beyond XSLT version 1.0, you may need it in future ..
:)
Yes you can - you can include
and import
other XSLTs.
This is a good place to start learning about import
which is what you are looking for specifically. include
is different but worth knowing about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With