Skip to content Skip to sidebar Skip to footer

How Can I Add Header And Footer Xslt Files To Another Xslt File To Convert It Into Html?

I am coding a XSLT program, which will convert XML to HTML format. I want to add header and footer to XSLT. It mean that I am thinking to add header.xslt and footer.xslt in my cont

Solution 1:

How can I include these two xslt files to content.xslt ? I have tried import but not getting the correct results.

You have two main issues to tackle.

In the first place, you need the transformations defined in the separate header and footer stylesheets to be presented inside the main transformation. You don't show any mechanism for doing that, but it's not hard: you need to insert apply-templates elements at the appropriate places in the main template. It may be useful to use non-default modes for the header and footer templates. For example,

content.xslt:

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:templatematch="/"><html><body><!-- THIS: --><xsl:apply-templatesselect="."mode="header" /><h2>=======start content==========</h2><h2>The customer details are: </h2><!-- ... --></body></html></xsl:template></xsl:stylesheet>

In the second place, you need to incorporate the template(s) defined in your external files into the stylesheet defined in your main file. This is what the XSL import and include elements are for, but since you're already using import I guess I don't need to go into detail. Thus, it looks like this might fit into your scheme:

layout.xslt:

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:importhref="content.xslt" /><xsl:importhref="header.xslt" /><xsl:importhref="footer.xslt" /></xsl:stylesheet>

Note that no template is needed in this stylesheet; the imported stylesheets are being relied upon to provide all needed. You might then write the header stylesheet like this, for example:

header.xslt:

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><!-- note that this mode matches the one selected by the apply-templates
         in content.xslt: --><xsl:templatematch="/"mode="header"><h1>Header Content</h1></xsl:template></xsl:stylesheet>

Post a Comment for "How Can I Add Header And Footer Xslt Files To Another Xslt File To Convert It Into Html?"