Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Apr 19, 2013 @ 17:20
    Craig O'Mahony
    0

    Get the Properties of a node from it's name

    Hi,

    It is possible to get at a nodes properties if I know the name of the Node?

    For instance in my content tree I have some content that has the name of 'Test' and I want to return the bodyText field from this node. In XSLT I have a variable populated with the text of 'Test' but I can't seem to access this piece of content based on it's name?

    Can anyone help?

    Thanks,

    Craig

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 9x admin c-trib
    Apr 19, 2013 @ 23:13
    Chriztian Steinmeier
    1

    Hi Craig,

    Here's the basics of setting that up:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <xsl:template match="/">
            <!-- Find and process the Test node --> <xsl:apply-templates select="$siteRoot//*[@nodeName = 'Test']" />
        </xsl:template>
    
        <!-- Generic template for any Umbraco Document Node  -->
        <xsl:template match="*[@isDoc]">
            <div>
                <!-- Usually an RTE field, so need to disable output escaping -->
                <xsl:value-of select="bodyText" disable-output-escaping="yes" />
            </div>
        </xsl:template>
    
    </xsl:stylesheet>

     

    The double slash is a shortcut for the descendant:: axis which basically runs through the entire structure (here, below $siteRoot) so if you have more than one called "Test", they will all be processed.

    If you know roughly where it's located, a more specific XPath will perform better, especially in a large tree, e.g.:

    <xsl:apply-templates select="$siteRoot/Pages/Textpage[@nodeName = 'Test']" />

    Let's say you had 5 childnodes of $siteRoot - then you've just saved the processor the hassle of going down 4 of them, by specifying the "Pages" child.

    /Chriztian

  • Craig O'Mahony 364 posts 918 karma points
    Apr 22, 2013 @ 11:22
    Craig O'Mahony
    0

    Hi Chriztian,

    That's exactly what I wanted. Thanks a million :)

    Craig

  • 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