Umbraco库getMedia父节点属性xslt

时间:2013-01-10 05:06:53

标签: xslt properties umbraco parent

如何使用“umbraco.library:GetMedia”从媒体项的父节点获取属性?

这允许我获取当前节点“@nodeName”

<xsl:value-of select="umbraco.library:GetMedia(., 0)/@nodeName" />

我想获取当前节点“@nodeName”的父节点,我尝试了以下但是它不起作用:

<xsl:value-of select="umbraco.library:GetMedia(., 0)/../@nodeName" />

任何人都可以帮助我吗?

干杯,JV

1 个答案:

答案 0 :(得分:0)

通过调用GetMedia()和变量中的@parentID属性,我可以使用以下方法进行操作:

<xsl:template match="/">
        <!-- Do not call unless an image was picked -->
        <xsl:apply-templates select="$currentPage/image[normalize-space()]" />
</xsl:template>

<xsl:template match="image">
        <!-- Note: These WILL fail if no media is selected -->
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
        <xsl:variable name="parentMedia" select="umbraco.library:GetMedia($mediaNode/@parentID, false())" />

        <p>
                Media: <xsl:value-of select="$mediaNode/@nodeName" />
        </p>
        <p>
                Parent: <xsl:value-of select="$parentMedia/@nodeName" />
        </p>
</xsl:template>