Problem getting xml Options
Johan
Posted: Monday, May 12, 2008 4:50:42 PM
Rank: Newbie

Joined: 4/17/2008
Posts: 11
Location: Kalmar, Sweden
I'm trying to make a calendar package and have problem getting the calendar events from the xml nodes through an xslt file. My xslt file looks like this:
Code:

<?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" xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="/">
    <Events>
      <xsl:apply-templates select="descendant-or-self::node[@nodeTypeAlias='Kalenderhandelse']">
        <!-- <xsl:sort order="descending" select="data[@alias='eventDate']" data-type="text"/> -->
      </xsl:apply-templates>
    </Events>
  </xsl:template>

  <xsl:template match="node">
    <Event id="{position()}">
      <Title>
        <xsl:value-of select="@nodeName"/>
      </Title>
      <StartTime>
        <xsl:value-of select="data[@alias='startdatum']"/>
      </StartTime>
      <EndTime>
        <xsl:value-of select="data[@alias='slutdatum']"/>
      </EndTime>
      <URL>
        <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
      </URL>
    </Event>
  </xsl:template>
</xsl:stylesheet>

And the code in my controller looks like this:
Code:

            StringBuilder builder1 = new StringBuilder();
            StringWriter writer1 = new StringWriter(builder1);
            XmlTextWriter writer2 = new XmlTextWriter(writer1);
            XslTransform xsltrans = new XslTransform();
            XmlUrlResolver resolver = new XmlUrlResolver();
           
            XsltArgumentList xslArg = new XsltArgumentList();
            umbraco.library lib = new library();
            xslArg.AddExtensionObject("urn:umbraco.library", lib);
            xsltrans.Load(this.Context.Server.MapPath("~/xslt/Events.xslt"));
            resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
           
            XmlNode node = ((IHasXmlNode)library.GetXmlNodeById("1251").Current).GetNode();
            xsltrans.Transform(node.CreateNavigator().Select(".").Current,xslArg,writer2,resolver);

            writer1.Close();
            writer2.Close();

            return builder1.ToString();


And the only output i get is this:
Code:

<Events></Events>
drobar
Posted: Monday, May 12, 2008 5:28:59 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,408
Location: KY, USA
Just a quick thought here... does this line:
Code:
<xsl:apply-templates select="descendant-or-self::node ...


need to include $currentPage to work properly?

Code:
<xsl:apply-templates select="$currentPage/descendant-or-self::node ...


cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
Johan
Posted: Monday, May 12, 2008 6:44:45 PM
Rank: Newbie

Joined: 4/17/2008
Posts: 11
Location: Kalmar, Sweden
drobar wrote:
Just a quick thought here... does this line:
Code:
<xsl:apply-templates select="descendant-or-self::node ...


need to include $currentPage to work properly?

Code:
<xsl:apply-templates select="$currentPage/descendant-or-self::node ...


cheers,
doug.


Hi doug,

I added currentPage as you said but i can't get through to the XML. Can the problem be my C# coding?
drobar
Posted: Monday, May 12, 2008 6:56:36 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,408
Location: KY, USA
To be honest, I didn't even look at the c#. I assumed (maybe inappropriately) that since you got the <event></event> output that it was working.

But you're entirely correct that the problem could be there. Let's take this step by step to find the problem.

Based on the sample c# you provided, you're really just trying to do an xslt transformation on the node with an id of 1251. If that's the case, why bother with the c# at all? Maybe you want to do more in the c# later?

For now, let's make a test and see if the xslt is working properly. If it is then any issue is in the c#. If the xslt isn't working properly then we'll want to fix it first.

Create a new macro and select the Events.xslt file. Put a checkmark in the 'use in editor' box, remove the checkbox from 'render in editor' box. Save the macro.

Go to the content node that is has id 1251. Insert the macro you just made (assuming you have a richtext editor on that document type; if not, insert the macro in the template used by this node). Save and publish.

Do you get back the proper output from your xslt macro when you visit the page with a browser? You might want to put in some <xsl:value-of...> output for debugging. Also, perhaps use an <xsl:call-template...> with a named template rather than using the <xsl:template match="node"> format.

When the xslt is working properly you can either use that macro, or call the xslt from c# and a .net usercontrol macro instead. But unless you're doing a lot of extra work in the c# it would be cleaner to use the xslt macro directly.


Let us know what you find out.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
Johan
Posted: Tuesday, May 13, 2008 12:08:00 PM
Rank: Newbie

Joined: 4/17/2008
Posts: 11
Location: Kalmar, Sweden
Yup, getting all nodes i want to use will be my next step, right now i'm just trying to get any xml at all. I get the xslt to work the way you described it. What i'm trying to get is all the events in my calendar on a certain month and year.

Edit: Here is an image over the structure


Edit2: I just discovered nodeFactory :D Thanks for the help Doug!
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.