I’m having trouble obtaining data with a macro I’ve created using XSLT. I have several EventData nodes which I would like to access from a page in another Content folder.
I’ve tried many different queries (too many to post) but my latest one is below. I had this working when the Event Data was below the standard page but I have since moved them to their own folder and haven’t managed to successfully update the XSLT.
XML:
<root id="-1">
<HomeTemplate id="1055" parentID="-1" level="1">
<ContentFolder id="1097" parentID="1055" level="2">
<EventData id="1095" parentID="1097" level="3">
<eventDate>2012-06-20T00:00:00</eventDate>
<eventName>Event Name Data</eventName>
<eventLocation>Event Location Data</eventLocation>
</EventData>
.......
</ContentFolder>
<ContentFolder id="1059" parentID="1055" level="2">
<StandardTemplate id="1061" parentID="1059" level="3">
<pageHeading>Results</pageHeading>
.......
</StandardTemplate>
</ContentFolder>
......
</HomeTemplate>
</root>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<table>
<xsl:for-each select="EventData">
<tr>
<td>Event Date: <xsl:value-of select="umbraco.library:FormatDateTime(./eventDate, 'd')"/></td>
<td>Event Name: <xsl:value-of select="./eventName"/></td>
<td>Event Location: <xsl:value-of select="./eventLocation"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
EDIT:
<xsl:for-each select="umbraco.library:GetXmlNodeById(1097)/EventData">
The above works but I ideally want something that would select by type so isn’t hard coded.
Old Schema
New Schema
Please note this example walks upto the top level node/document type with the alias of HomeTemplate as I presume the most top level node you are using has only one instance.
Also note this is a fairly expensive xPath call as it walks up the tree to find the top level node until we get to the Home node. Then it looks through all the child nodes no matter how deep to find the node (document type) with the alias of EventData.
Source: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema