How to share code among several transformations

I have several transformations, that are using the very same functionality (extracted to xsl:template). Is there a way to have such functionality in one place?

You can share xslt code easily:

  1. Create a separate XSLT containing your template
  2. Use <xsl:include href="model://_xslt_template_id"> in your other stylesheets. Your shared template will be available.

You can also use <xsl:import/>.

Difference between xsl:include and xsl:import

<xsl:include/> will include all the templates in the included stylesheet. You cannot have a template with the same name in your own stylesheet. See http://www.w3schools.com/xsl/el_include.asp

<xsl:import/> will also include all the templates but you can override those templates if you include a template with the same name in your own stylesheet. See http://www.w3schools.com/xsl/el_import.asp.

1 Like