Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I link xslt to another xslt?

Tags:

xml

xslt

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!

like image 743
c00ke Avatar asked Feb 10 '09 16:02

c00ke


4 Answers

<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.

like image 147
matpie Avatar answered Sep 28 '22 09:09

matpie


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.

like image 36
Dimitre Novatchev Avatar answered Sep 28 '22 08:09

Dimitre Novatchev


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 ..
:)

like image 24
InfantPro'Aravind' Avatar answered Sep 28 '22 07:09

InfantPro'Aravind'


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.

like image 40
Andrew Hare Avatar answered Sep 28 '22 09:09

Andrew Hare