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?
<?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.:
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.
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
Hi Craig,
Here's the basics of setting that up:
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.:
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
Hi Chriztian,
That's exactly what I wanted. Thanks a million :)
Craig
is working on a reply...