Though your reasoning is 100% correct, the problem is that you're only getting the XML for the requested item, without its context. So you need to do one of two things - either:
Grab all the media XML once, and then use XPath to select the items you need, or...
Use a second call to GetMedia() with the @parentID attribute of the first, to get to its parent
Which option to choose depends on the size of your Media library and on how much you're hitting this functionality, i.e., if you're oing to do this for a bunch of items or just for a few? If you're just doing this for a couple of items, use #2 and do something like this:
<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>
Note that I'm assuming the property alias image for the property - change to suit your setup.
It's more or less the same problem - in $mediaNode you only have the XML for that one item. And in parentMedia, you only have the parent's XML - the mediaNode's siblings aren't present in either of those - BUT - if you set the boolean flag to true() on $parentMedia, you'll suddenly have all of mediaNode's siblings (plus their children and their children etc.) - so:
<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, true())" />
<p>
Media: <xsl:value-of select="$mediaNode/@nodeName" />
</p>
<p>
Parent: <xsl:value-of select="$parentMedia/@nodeName" />
</p>
<p> Following sibling: <xsl:value-of select="$parentMedia/*[@id = $mediaNode/@id]/following-sibling::*[1]/@nodeName" /> </p>
</xsl:template>
Umbraco library GetMedia parent node property
How can I get a property from the parent node of a media item using "umbraco.library:GetMedia"?
This allows me to get the current nodes "@nodeName"
I want to get the parent of the current nodes "@nodeName", I've tried the following but it doesn't work:
Can anyone help me out?
Cheers, JV
Hi JV,
Though your reasoning is 100% correct, the problem is that you're only getting the XML for the requested item, without its context. So you need to do one of two things - either:
Which option to choose depends on the size of your Media library and on how much you're hitting this functionality, i.e., if you're oing to do this for a bunch of items or just for a few? If you're just doing this for a couple of items, use #2 and do something like this:
Note that I'm assuming the property alias image for the property - change to suit your setup.
/Chriztian
Thanks Chriztian, that is perfect for what I need. I greatly appreciate your help.
How can I get properties from the mediaNodes "following-sibling"?
Hi again - hadn't seen the bonus question :-)
It's more or less the same problem - in $mediaNode you only have the XML for that one item. And in parentMedia, you only have the parent's XML - the mediaNode's siblings aren't present in either of those - BUT - if you set the boolean flag to true() on $parentMedia, you'll suddenly have all of mediaNode's siblings (plus their children and their children etc.) - so:
/Chriztian
Thanks again Chriztian, that has worked perfectly! Cheers, JV
is working on a reply...