Can I use a master xsl file to be used for other xsl files?

Dear Experts:

My requirement is to define a master template (that contains header, footer and other common details) for all the other detail xsl files to consume.
Please provide sample implementation, The current tool I am using is Ecrion Designer if you can provide samples as EPR files will be great but xsl files will do as well.


LVL 37
Miguel OzSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
I am not in a position to provide sample code on my phone

But i do this a lot

Have a seperate xslt file that has the template for the document node
I use that file as the “skin” put the header and the footer in the main template
Inside the body I call a named template

Then where your logic is make an xsl:import ( not xsl:include !!! )
Define the named template for content processing in the importing stylesheet
And apply templates inside the named template for the other nodes

Thatbis all there is to it
Changing the skin is easy, just import a different skin xslt
I use that for an equal,look and feel on different documents accross projects
Gertone (Geert Bormans)Information ArchitectCommented:
I also have standard libraries that build xsl:fo fragments that could be reused accross templates
Miguel OzSoftware EngineerAuthor Commented:
Import looks promising if you could provide some sample code or links with samples will be great
Gertone (Geert Bormans)Information ArchitectCommented:
I would imagine you could figure most of it out from the explanation I gave

I just pulled a skin out of one of my projects

- it is XSLT2, so using functions instead of named templates, so you need to swap that for XSLT1
- it is for html not FO

	<xsl:function name="fun:html-skin">
		<xsl:param name="context" as="element()"/>
			    <title><xsl:value-of select="$skin-html-head-title"/></title>
				<xsl:copy-of select="fun:build-css-references()"/>
				<div id="header">
					<xsl:copy-of select="fun:build-html-header()"/>
				<xsl:copy-of select="fun:build-html-body($context)"/>

				<div id="footer">
					<xsl:copy-of select="fun:build-html-footer()"/>
				<xsl:copy-of select="fun:build-javascript-references()"/>
	<!-- materialisation of the function that renders the actual content -->
	<xsl:function name="fun:build-html-body">
		<xsl:param name="context" as="element()"/>
		<div id="content">
			<xsl:apply-templates select="$context"></xsl:apply-templates>
	<!-- requires implementation in the calling stylesheet -->
	<xsl:function name="fun:get-type-specific-content">
		<xsl:param name="context"/>
	<!-- requires implementation in the calling stylesheet -->
	<xsl:function name="fun:build-html-header">
	<xsl:function name="fun:build-html-footer">
	<!-- FAVICON -->
	<xsl:function name="fun:set-favicon-references">
		<!-- standard should be replaced -->
	<!-- CSS references -->
	<xsl:function name="fun:build-css-references">
		<xsl:copy-of select="fun:build-css-references-core()"/>
		<xsl:copy-of select="fun:build-css-references-domain()"/>
		<xsl:copy-of select="fun:build-css-references-application()"/>
	<xsl:function name="fun:build-css-references-core">
		<!-- standard should be replaced -->
	<xsl:function name="fun:build-css-references-domain">
		<!-- standard should be replaced -->
	<xsl:function name="fun:build-css-references-application">
		<!-- standard should be replaced -->

	<!-- javascript references -->
	<xsl:function name="fun:build-javascript-references">
		<xsl:copy-of select="fun:build-javascript-references-core()"/>
		<xsl:copy-of select="fun:build-javascript-references-domain()"/>
		<xsl:copy-of select="fun:build-javascript-references-application()"/>
	<xsl:function name="fun:build-javascript-references-core">
		<script src="/js/jquery-3.1.1.min.js">_</script>
	<xsl:function name="fun:build-javascript-references-domain">
		<!-- standard should be replaced -->
	<xsl:function name="fun:build-javascript-references-application">
		<!-- standard should be replaced -->

Open in new window

Gertone (Geert Bormans)Information ArchitectCommented:
you need to call this function from the template matching /, passing the root element as the context parameter
<xsl:function name="fun:html-skin">
            <xsl:param name="context" as="element()"/>

and you need a redefinition of each stub function at the higher level stylesheets,
the ones in my skin are empty

redefinition only works on xsl:import, that is why you must not  use xsl:include to make this work

I guess you can work from here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.