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.
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:
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.
<!-- 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?
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-eachselect="$currentPage/node[not(data[@alias = 'umbracoNaviHide'] = 1)]"> <!-- Display the posts author (content picker, on doc type) --> <span>
<xsl:value-ofselect="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.)
Node property from another node using GetXmlNodeById
I have the following XSLT snippet:
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
Hi Daniel, welcome to Our Umbraco.
You were close, but there is a slight syntax error with your XPath. Try this:
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.
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:
this returned nothing... Is this normal behaviour or am I completed missing something here?
Cheers, Daniel
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
Here is some additional syntax:
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
Hi Daniel,
Hmmm... I'd take a step back and see what's going on inside the data/values. Try the following:
... then if that returns a value, then try ...
... 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.
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:
(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
Just had a "DOH!" moment, Chriztian is correct, it's the extra "/node" that is throwing you off!
Thanks for your help, after reading Chriztian's comment I felt like a **** :) Thanks for all your help.
is working on a reply...