Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 17:55
    Dan
    0

    Get name of parent node

    Hi,

    Can anyone see how to get this working?  I'm selecting all nodes with particular tags, but I want to include the name of the parent node with them:

    <xsl:for-each select="umbraco.library:GetXmlNodeById(number($source))/descendant::node [contains(Exslt.ExsltStrings:lowercase(./data [@alias='galleryImageTags']), Exslt.ExsltStrings:lowercase(string($tag)))]">
    <xsl:variable name="galleryName" select="parent/data [@nodeName]"/>
    </xsl:for-each>

    I just can't get the value for 'galleryName' to return anything, so it's probably a syntax problem with that line.

    Thanks all...

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 18:04
    Lee Kelleher
    0

    Hi Dan,

    Try, "parent::node":

    <xsl:variable name="galleryName" select="parent::node/data [@nodeName]"/>

    You can read more about XPath Axes here:

    http://www.w3schools.com/xpath/xpath_axes.asp

    Cheers, Lee.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 18:06
    Lee Kelleher
    1

    Oops, sorry, didn't look at the XSLT properly. (my bad)

    Do this:

    <xsl:variable name="galleryName" select="parent::node/@nodeName" />

    It's not in the "data" node, but an attribute of the "node" node instead.

    Cheers, Lee.

  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 18:14
    Dan
    0

    Again, you dig me out of a hole Lee, thanks.  I definitely need to read up on XPath and more on XSLT in general as I'm doing some pretty involved stuff at the moment and seem to get stuck with it every 2 minutes!  Speaking of which...  I implemented the code above but it's not returning anything still.  The whole code is as follows (employs your media checking script from your earlier post today):

    <ul class="gallery-thumbnails">
    <xsl:for-each select="umbraco.library:GetXmlNodeById(number($source))/descendant::node [contains(Exslt.ExsltStrings:lowercase(./data [@alias='galleryImageTags']), Exslt.ExsltStrings:lowercase(string($tag)))]">
    <xsl:variable name="galleryName" select="parent::node/data [@nodeName]"/>
    <xsl:variable name="nodeName" select="@nodeName"/>
    <xsl:variable name="mediaId" select="number(current()/data[@alias='galleryImage'])" />
    <xsl:variable name="material" select="string(current()/data[@alias='galleryMaterial'])" />
    <xsl:if test="$mediaId &gt; 0">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
    <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">
    <xsl:variable name="fullSizeFile" select="$mediaNode/data[@alias='umbracoFile']"/>
    <li>
    <a href="{$fullSizeFile}" rel="shadowbox[{$galleryName}]" title="{$galleryName} : {@nodeName}">
    <img src="/umbraco/imagegen.ashx?image={$fullSizeFile}&amp;width=80&amp;height=80&amp;constrain=true" alt="{@nodeName}" title="{$galleryName} : {@nodeName}" />
    </a>
    </li>
    </xsl:if>
    </xsl:if>
    </xsl:for-each>
    </ul>

    It should be putting the $galleryName value into the title attribute of the anchor and the image tags, but it's just blank.  It can't be due to casing this time as @nodeName is part of the umbraco core library, so I'm confused.

  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 18:15
    Dan
    0

    We must have cross-posted there sorry.  Your second solution works perfectly, thanks again!

  • Petr Snobelt 923 posts 1535 karma points
    Feb 05, 2010 @ 18:15
    Petr Snobelt
    4

    or

    <xsl:variable name="galleryName" select="./../@nodeName" />
Please Sign in or register to post replies

Write your reply to:

Draft