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.

Thanks,

MAS
LVL 36
Miguel OzSoftware EngineerAsked:
Who is Participating?
 
Geert BormansInformation 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
0
 
Geert BormansInformation 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
0
 
Geert BormansInformation ArchitectCommented:
I also have standard libraries that build xsl:fo fragments that could be reused accross templates
0
 
Miguel OzSoftware EngineerAuthor Commented:
Import looks promising if you could provide some sample code or links with samples will be great
0
 
Geert BormansInformation 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

Caveat
- 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:output 
    	method="html"
    	version="5.0"
    	indent="yes"
    	encoding="UTF-8"
    	omit-xml-declaration="yes"
    	media-type="text/html"
	/>
	
	
	<xsl:function name="fun:html-skin">
		<xsl:param name="context" as="element()"/>
		<html>
			<head>
			    <title><xsl:value-of select="$skin-html-head-title"/></title>
				<xsl:copy-of select="fun:build-css-references()"/>
			</head>
			<body>
				<div id="header">
					<xsl:copy-of select="fun:build-html-header()"/>
				</div>
				
				<xsl:copy-of select="fun:build-html-body($context)"/>

				<div id="footer">
					<xsl:copy-of select="fun:build-html-footer()"/>
				</div>
				<xsl:copy-of select="fun:build-javascript-references()"/>
			</body>
		</html>
	</xsl:function>
	
	<!-- 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>
		</div>
	</xsl:function>
	
	<!-- requires implementation in the calling stylesheet -->
	<xsl:function name="fun:get-type-specific-content">
		<xsl:param name="context"/>
	</xsl:function>
	
	<!-- requires implementation in the calling stylesheet -->
	<xsl:function name="fun:build-html-header">
		<div>[STANDARD HEADER NEEDS REPLACING]</div>
	</xsl:function>
	
	<xsl:function name="fun:build-html-footer">
		<div>[STANDARD FOOTER NEEDS REPLACING]</div>
	</xsl:function>
	
	<!-- FAVICON -->
	
	<xsl:function name="fun:set-favicon-references">
		<!-- standard should be replaced -->
	</xsl:function>
	
	<!-- 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>
	
	<xsl:function name="fun:build-css-references-core">
		<!-- standard should be replaced -->
	</xsl:function>
	
	<xsl:function name="fun:build-css-references-domain">
		<!-- standard should be replaced -->
	</xsl:function>
	
	<xsl:function name="fun:build-css-references-application">
		<!-- standard should be replaced -->
	</xsl:function>

	<!-- 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>
	
	<xsl:function name="fun:build-javascript-references-core">
		<script src="/js/jquery-3.1.1.min.js">_</script>
	</xsl:function>
	
	<xsl:function name="fun:build-javascript-references-domain">
		<!-- standard should be replaced -->
	</xsl:function>
	
	<xsl:function name="fun:build-javascript-references-application">
		<!-- standard should be replaced -->
	</xsl:function>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.