测试结果树片段
Test for result tree fragment
我正在尝试创建一个模板,该模板要么显示一些内容,要么插入一个占位符以指示缺少内容:
<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>
这很好用,直到 content
是一个结果树片段:
<xsl:call-template name="information">
<xsl:with-param name="content">Yes</content>
</xsl:call-template>
我正在使用 Microsoft .NET XSLT 引擎,因此我可以调用 msxsl:node-set()
参数来获得可用的节点集,但我不知道如何测试参数是否需要这个治疗。到目前为止,生成内容的情况较少。
有没有办法让这个模板适用于适当的节点集 和 结果树片段?
XslCompiledTransform
在 .NET 2.0 及更高版本中支持 exsl:object-type
http://exslt.org/exsl/functions/object-type/index.html 因此您可以根据需要检查变量的类型。另一方面,我认为在节点集而不是结果树片段上调用 msxsl:node-set
没有问题,它只是 returns 节点集不变。
我正在尝试创建一个模板,该模板要么显示一些内容,要么插入一个占位符以指示缺少内容:
<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>
这很好用,直到 content
是一个结果树片段:
<xsl:call-template name="information">
<xsl:with-param name="content">Yes</content>
</xsl:call-template>
我正在使用 Microsoft .NET XSLT 引擎,因此我可以调用 msxsl:node-set()
参数来获得可用的节点集,但我不知道如何测试参数是否需要这个治疗。到目前为止,生成内容的情况较少。
有没有办法让这个模板适用于适当的节点集 和 结果树片段?
XslCompiledTransform
在 .NET 2.0 及更高版本中支持 exsl:object-type
http://exslt.org/exsl/functions/object-type/index.html 因此您可以根据需要检查变量的类型。另一方面,我认为在节点集而不是结果树片段上调用 msxsl:node-set
没有问题,它只是 returns 节点集不变。