Copied to clipboard

Flag this post as spam?

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


  • Daniel Draper 36 posts 57 karma points
    Mar 29, 2010 @ 03:24
    Daniel Draper
    0

    Node property from another node using GetXmlNodeById

    I have the following XSLT snippet:

    <p class="meta"><xsl:value-of select="Exslt.ExsltDatesAndTimes:formatdate($currentPage/@createDate, 'MMM dd')" /><span><xsl:value-of select="umbraco.library:GetXmlNodeById(data [@alias = 'postAuthor'])/node [string(data [@alias='authorName'])]" /></span></p>

    The propety postAuthor is an ID of the authors node. I would like to display the authors name from the authors node. I figured this should work but it doesn't and it doesn't display an error.

    Any help would be appreciated.

     

    Regards,

    Daniel Draper

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Mar 29, 2010 @ 09:53
    Lee Kelleher
    0

    Hi Daniel, welcome to Our Umbraco.

    You were close, but there is a slight syntax error with your XPath.  Try this:

    <span><xsl:value-of select="umbraco.library:GetXmlNodeById(data[@alias='postAuthor'])/node/data[@alias='authorName']" /></span>
    

    In your version, you were returning the "node" element, and not the "data[@alias='authorName']" value.

    Let us know how you get on.

    Cheers, Lee.

  • Daniel Draper 36 posts 57 karma points
    Mar 29, 2010 @ 12:45
    Daniel Draper
    0

    Thanks for the reply Lee, I adjusted my XPath as sugguested by your example but again the macro rendered with no error and without the value that should be appearing. I also adjusted the syntax as follows:

    <span><xsl:value-of select="umbraco.library:GetXmlNodeById(data[@alias='postAuthor'])/node/@id" /></span>

    this returned nothing... Is this normal behaviour or am I completed missing something here?

     

    Cheers, Daniel

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 29, 2010 @ 13:02
    Jan Skovgaard
    1

    I'm asuming that you somehow have a relation on you current post, right? Then you would need to add the $currenPage parameter into you selection I guess?

    Otherwise I don't really get how you would fetch the ID without hardcoding it.

    So I think your expression should look like this:

    <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/data[@alias='postAuthor'])/node/@id" />

    /Jan

  • Daniel Draper 36 posts 57 karma points
    Mar 29, 2010 @ 13:22
    Daniel Draper
    0

    Here is some additional syntax:

    <!-- Loop through each blog post -->
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <!-- Display the posts author (content picker, on doc type) -->
    <span><xsl:value-of select="umbraco.library:GetXmlNodeById(data[@alias='postAuthor'])/node/data[@alias='authorName']" /></span>
    </xsl:for-each>

    Doing a value-of on just data[@alias = 'postAuthor'] returns the nodeID of the author node as expected. So I assume this is still an XPath issue?

     

    Cheers, Daniel

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Mar 29, 2010 @ 14:23
    Lee Kelleher
    0

    Hi Daniel,

    Hmmm... I'd take a step back and see what's going on inside the data/values.  Try the following:

    <xmp>
        <xsl:copy-of select="data[@alias='postAuthor']" />
    </xmp>

    ... then if that returns a value, then try ...

    <xmp>
        <xsl:copy-of select="umbraco.library:GetXmlNodeById(data[@alias='postAuthor'])" />
    </xmp>

    ... to see if that returns the XML from GetXmlNodeById?

    Let us know what it returns.  Hopefully, we'll figure this out soon.

    (Personally, I think its something to do with Jan's suggestion ... the context of $currentPage?)

    Cheers, Lee.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Mar 29, 2010 @ 21:57
    Chriztian Steinmeier
    1

    Hi Daniel,

    It's indeed an XPath issue, from what I can see - when you call GetXmlNodeById() you get a <node> element back, so you should take the <data> straight from that one:

    <!-- Loop through each blog post -->
    <xsl:for-each select="$currentPage/node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
       
    <!-- Display the posts author (content picker, on doc type) -->
       
    <span> <xsl:value-of select="umbraco.library:GetXmlNodeById(data[@alias = 'postAuthor'])/data[@alias = 'authorName']" /> </span>
    </xsl:for-each>

    (You version has an extra 'node' after the method call, which will go to the child node of the returned node, before taking the data element.)

    /Chriztian

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Mar 29, 2010 @ 22:21
    Lee Kelleher
    0

    Just had a "DOH!" moment, Chriztian is correct, it's the extra "/node" that is throwing you off!

  • Daniel Draper 36 posts 57 karma points
    Mar 29, 2010 @ 23:58
    Daniel Draper
    0

    Thanks for your help, after reading Chriztian's comment I felt like a **** :) Thanks for all your help.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies