I am trying to basically recreate the functionality of an ASP.NET master page with an XSLT template.
I have a “master page” template that contains much of the page html stored in an .xslt file. I have another .xslt file specific to a single page, that takes in xml representing the page data. I want to call the master page template from my new template, and still have the ability to insert my own xml that will be applied. If I could pass a param that would allow me to call template with the param as the name, that would do the trick, but that doesn’t appear to be allowed.
Basically I have this:
<xsl:template name="MainMasterPage">
<xsl:with-param name="Content1"/>
<html>
<!-- bunch of stuff here -->
<xsl:value-of select="$Content1"/>
</html>
</xsl:template>
And this:
<xsl:template match="/">
<xsl:call-template name="MainMasterPage">
<xsl:with-param name="Content1">
<h1>Title</h1>
<p>More Content</p>
<xsl:call-template name="SomeOtherTemplate"/>
</xsl:with-param>
</xsl-call-template>
</xsl:template>
What happens is that the nested xml is basically stripped and all that is inserted is “TitleMore Content”
The problem with the provided code is here:
This will output either the concatenation of all text-nodes descendents of the top node of
$Content1(if it contains a document) or the string value of its first element or text child (if it is an XML fragment).You need to use
<xsl:copy-of select='$pContent1'>instead of
<xsl:value-of select='$pContent1'>.This correctly copies all children nodes of
$pContent1Below is a corrected transformation:
When this transformation is applied on any XML document (not used), the wanted, correct result is produced: