Copied to clipboard

Flag this post as spam?

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


  • radmanmm 117 posts 108 karma points
    Jun 23, 2009 @ 23:42
    radmanmm
    0

    Can't ever seem to get the basic XSLT tasks to work

    Hi All,

    As always I have become very frustrated with the XSLT work in umbraco.  I have been coding for 2 decades and xslt seems to spank me every time.

    Why is it that I cannot seem to do something as simple as find a node by id?  Anyone have an idea on how that should work because statements like this clearly do not.

    select="/descendant::node/@id = '1047'"

    neither does this

    select="/descendant::node [@id = '1047']"

    nor do any other variant I have tried.

    Any thoughts would be greatly appreciated.

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Jun 24, 2009 @ 00:20
    Tom Madden
    2

    You can use this snippet to get data from a specific node:

    <xsl:value-of select="umbraco.library:GetXmlNodeById(3106) [@alias = 'myProperty']" />

    obviously you change the nodeId and the property name to suit your project. I agree that XSLT take a bit of getting used to, and I tend to gather snippets of useful information and keep them for future use. I just used the one above this evening. There may be another way to do this, plus you can extend this by putting the nodeId into a variable which can be passed in through a macro parameter as a content picker allowing you to be presented with a content picker each time you insert the macro which calls the XSLT saving you having to hard code the nodeId into the XSLT file. Of course there may be otehr ways to achieve this same result, but this is the one I've used. HTH Tom

  • kmacdonell 28 posts 45 karma points
    Jun 24, 2009 @ 00:22
    kmacdonell
    2

    umbraco.library:GetXmlNodeById(1047) should return the node.

    select="$currentPage/descendant::node [@ID = 1047]" should return the node if the node is a descendant of the current page.

    Hope this helps, Kev

  • Paul Blair 466 posts 731 karma points
    Jun 24, 2009 @ 01:34
    Paul Blair
    2

    Or this to locate it anywhere in the structure:

    $currentPage/ancestor::root//node [@ID = 1047]

    I'm not sure about the GetXmlNodeById call mentioned above. Does it call the database and therefore have a possible negative impact on performance?

  • radmanmm 117 posts 108 karma points
    Jun 24, 2009 @ 02:40
    radmanmm
    0

    Wow guys you are are phenomenal!

  • Jesper Hauge 298 posts 487 karma points c-trib
    Jun 24, 2009 @ 09:42
    Jesper Hauge
    1

    I'm pretty sure the GetXmlNodeById does not call the database, but rather searches through the cached pages and the xml in umbraco.config. The consensus about the methods in umbraco.library seems to be that only calls to certain methods related to the media section content causes visits to the database.

    Regards
    Hauge

Please Sign in or register to post replies

Write your reply to:

Draft