I'm trying to create a template which either presents some content, or inserts a placeholder to indicate the absence of the content:
<xsl:template name="information">
<xsl:param name="content">
<xsl:choose>
<xsl:when test="$content">
<Content>
<xsl:apply-templates select="$content/node()" />
</Content>
</xsl:when>
<xsl:otherwise>
<PlaceHolder/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This works well, until content
is a result tree fragment:
<xsl:call-template name="information">
<xsl:with-param name="content">Yes</content>
</xsl:call-template>
I'm using the Microsoft .NET XSLT engine, so I can call msxsl:node-set()
on a parameter to obtain a workable node-set, but I don't know how to test if the parameter needs this treatment. It is by far the lesser case that the content is generated.
Is there a way to make this template work for proper node-sets and result tree fragments?
XslCompiledTransform
in .NET 2.0 and later supports exsl:object-type
http://exslt.org/exsl/functions/object-type/index.html so you can check the type of your variable if needed. On the other hand I don't think there is a problem in calling msxsl:node-set
on a node set instead of a result tree fragment, it simply returns the node set unchanged.