Not sure exactly what you mean by dynamic path, but one problem with the above is you should just be referencing $imagePosition, not $currentPage/$imagePosition (assuming you are wanting to reference the variable you defined and not a field on the page)
I'm guessing you're trying to name the property that holds the mediaId - so you'll need to use the name() function - here's a slightly rewritten sample to get you going:
<xsl:template match="/">
<!-- Grab the property right away - will not throw exception -->
<xsl:variable name="imagePosition" select="$currentPage/*[name() = /macro/position]" />
<!-- If there was a value -->
<xsl:if test="normalize-space($imagePosition) ">
<xsl:variable name="file" select="umbraco.library:GetMedia($imagePosition, false())" />
<!-- Handle file, whether Image, File, Folder or whatever -->
<xsl:apply-templates select="$file[not(error)]" />
</xsl:if>
</xsl:template>
<!-- Template for Image -->
<xsl:template match="Image">
<img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
</xsl:template>
Dynamic path in xslt
Hi
Im trying to figure out a way to use a dynamic path in my expressions
<xsl:template match="/">
<xsl:variable name="imagePosition" select="/macro/position" />
<xsl:if test="$currentPage/$imagePosition!='' and number($currentPage/$imagePosition)!=0">
<xsl:variable name="file" select="umbraco.library:GetMedia(number($currentPage/$imagePosition),'false')"/>
<xsl:if test="not($file/error)">
<img src="{$file/umbracoFile}"/>
</xsl:if>
</xsl:if>
</xsl:template>
But ofcourse it fails misserably. Is there an eval of some sort?
Thanks for any input
Hi,
Not sure exactly what you mean by dynamic path, but one problem with the above is you should just be referencing $imagePosition, not $currentPage/$imagePosition (assuming you are wanting to reference the variable you defined and not a field on the page)
-Tom
Looks like $imagePosition is the media item's id so Tom's solution will fix it.
xslt variables are accessed by themselves ($imagePosition)
page properties are accessed as children of the current page ($currentPage/propertyName)
Hi Eric,
I'm guessing you're trying to name the property that holds the mediaId - so you'll need to use the name() function - here's a slightly rewritten sample to get you going:
/Chriztian
Thumbs Up, Eric!
is working on a reply...