我有以下XSLT代碼,列出了指定節點中的文件夾及其文件項。XSLT xsl:apply-templates有條件語法
這一切工作正常,但我想參數化頁面,並有選擇地過濾其標籤值的輸出。
作爲一個XLST numpty我對於有條件的語法難以置信,我應該在<xsl:when test="$tag">
條款下 - 可有人請幫忙嗎?
<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>
您需要編輯這篇文章並將您的單引號切換爲備份,以便代碼在您的代碼片段上方的解釋中不會消失。 back-ticks與tilda相同。 –
好問題,+1。看到我的答案是一個簡單,簡單和簡單的解決方案。 :) –