XSLT xsl:应用模板条件语法
我有以下XSLT代码,它列出了指定节点中的文件夹及其文件项 这一切都很好,但我想参数化页面,并有选择地通过标记值过滤其输出 作为一个XLST numpty,我被我应该放在XSLT xsl:应用模板条件语法,xslt,umbraco,Xslt,Umbraco,我有以下XSLT代码,它列出了指定节点中的文件夹及其文件项 这一切都很好,但我想参数化页面,并有选择地通过标记值过滤其输出 作为一个XLST numpty,我被我应该放在子句下的条件的语法难住了-有人能帮忙吗 <xsl:variable name="tag" select="umbraco.library:Request('tag')" /> <xsl:template match="/"> <!-- Root folder
子句下的条件的语法难住了-有人能帮忙吗
<xsl:variable name="tag" select="umbraco.library:Request('tag')" />
<xsl:template match="/">
<!-- Root folder in Media that holds the folders to output -->
<xsl:variable name="mediaRootFolderId" select="5948" />
<!-- Pass in true() to get XML for all nodes below -->
<xsl:variable name="mediaRootNode" select="umbraco.library:GetMedia($mediaRootFolderId, true())" />
<xsl:choose>
<xsl:when test="$tag">
</xsl:when>
<xsl:otherwise>
<!-- If we didn't get an error, output Folder elements that contain Image elements -->
<xsl:apply-templates select="$mediaRootNode[not(error)]/Folder[File]" >
<xsl:sort select="@nodeName"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Template for folders -->
<xsl:template match="Folder">
<div class="folder">
<h2>Folder: <xsl:value-of select="@nodeName" /></h2>
<div class="images">
<xsl:apply-templates select="File">
<xsl:sort select="@nodeName"/>
</xsl:apply-templates>
</div>
</div>
</xsl:template>
<!-- Template for files -->
<xsl:template match="File">
File: <a href="{umbracoFile}" alt="{@nodeName}" ><xsl:value-of select="@nodeName" /></a> <br/>
</xsl:template>
文件夹:
文件:
您可以测试$tag是否设置为这样
<xsl:param name="tag">
<xsl:message terminate="yes">
$tag has not been set
</xsl:message>
</xsl:param>
$tag尚未设置
虽然这不是标准的,但它可以在大多数XSLT处理器上使用
如果希望绝对保存,可以将该值设置为非法值(例如1 div 0),并在模板主体中对其进行测试:
<xsl:param name="tag" select="1 div 0" />
<xsl:if test="$tag = 1 div 0">
<xsl:message terminate="yes">
$tag has not been set, or has been set to Infinity, which is invalid.
</xsl:message>
</xsl:if>
$tag尚未设置,或已设置为无穷大,这是无效的。
来源:O'Reilly XSLT Cookbook使用:
<xsl:apply-templates select=
"$mediaRootNode[not($tag)][not(error)]
/Folder[File]" >
解释:对于上面的
选择
属性中的XPath表达式,要选择一组非空的节点,必须将布尔($tag)
设置为true()
。因此,上面的单个
指令相当于问题中的长
。您需要编辑此帖子,并将单引号切换为反勾号,这样代码就不会在您的代码尖头上方的解释中消失。后面的记号和tilda在同一个键上。问得好,+1。请参阅我的答案,以获得简单、简短的解决方案。:)