1
votes

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 "&#x00A0;"> ]>
<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.

2
The select="EventData" on the for-each doesn't look like it going to find anything... have you tried select="//EventData"?freefaller
@freefaller I tried your suggestion but still doesn't generate any content. Any more ideas? How come my example wont find anything - is it looking at the wrong level?benni_mac_b
Is it outputting the <table> (therefore proving it's entering the template correctly)?freefaller
@freefaller Yes I just get '<table></table>'benni_mac_b
Have you tried with <xsl:output method="html"/>?freefaller

2 Answers

2
votes

Old Schema

<xsl:for-each select="$currentPage/ancestor-or-self::node[@nodeTypeAlias='HomeTemplate']//node[@nodeTypeAlias='EventData']">
</xsl:for-each>

New Schema

<xsl:for-each select="$currentPage/ancestor-or-self::HomeTemplate//EventData[@isDoc]">
</xsl:for-each>

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

0
votes

you are matching the root of the document (not the node 'root') and then looking for the node 'EventData'. That doesn't exist at that level, the only thing that exists there is <root>.

if you want to loop through the EventData, you need either

<xsl:for-each select="//EventData">
....

or

<xsl:for-each select="root/HomeTemplate/ContentFolder/EventData">
...

as the eventData is a long way up