Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Lawrence 128 posts 200 karma points
    Jul 16, 2010 @ 02:38
    Michael Lawrence
    0

    XPath expressions behaving strangely after update to 4.5

    Ok, so I've just upgraded my site from 4.0.2.1 to 4.5 and I'm experiencing some weird XPath behaviors in my XSLT.

    For example, the following works great:

    <xsl:for-each select="$calendarFeed/*[name()='feed']/*[name()='entry']">
         <xsl:value-of select="name()" /><br/>
    </xsl:for-each>

    However, the following shows nothing:

    <xsl:for-each select="$calendarFeed/feed/entry">
         <xsl:value-of select="name()" /><br/>
    </xsl:for-each>

    Any idea why this is happening? Maybe I've been working too long today and my brain is dead.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 16, 2010 @ 11:13
    Jan Skovgaard
    0

    Hi Michael

    Maybe you should try to output the returned XML from your calendarFeed variable in a <textarea> and copy/paste into an editor so you can see the structure of the returned XML. Maybe that will give you some pointers on how to solve your problem?

    I would do it like this: <textarea><xsl:copy-of select="$calendarFeed" /></textarea>

    /Jan

  • Michael Lawrence 128 posts 200 karma points
    Jul 16, 2010 @ 18:16
    Michael Lawrence
    0

    Hi Jan,

    Actually I've already done that and the XPath I'm using reflects the real structure of the XML.  I'm just pulling in some sample data from a Google Calendar feed.  Here's an example of a feed that I'm using:

    http://www.google.com/calendar/feeds/visioneducenter.com_n8u3g6vo6ifu0ln5ubrs9581s0%40group.calendar.google.com/public/full

    Again, the first code snippet works, but I'm not sure why the 2nd doesn't since they essentially do the exact same thing.

    Any ideas?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 16, 2010 @ 18:24
    Lee Kelleher
    3

    Hi Michael,

    It's the Atom namespace in the <feed> tag.  You'll need to declare it in your XSLT, (along with the other namespaces) like so:

    <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"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
        xmlns:gCal="http://schemas.google.com/gCal/2005"
        xmlns:gd="http://schemas.google.com/g/2005">
        exclude-result-prefixes="msxml umbraco.library atom openSearch gCal gd">

    Then you can reference the XML elements in your XPath statements... i.e.

    <xsl:for-each select="$calendarFeed/atom:feed/atom:entry">
        <xsl:value-of select="name()" /><br />
    </xsl:for-each>

    Let us know if it works for you.

    Cheers, Lee.

  • Michael Lawrence 128 posts 200 karma points
    Jul 16, 2010 @ 18:34
    Michael Lawrence
    0

    Hi Lee,

    Thanks so much, that works perfectly! I can't believe I forgot to declare the namespaces. Time to get some rest. Thanks again!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 16, 2010 @ 18:48
    Lee Kelleher
    0

    No worries Michael, glad you got it sorted.  The namespaces thing has caught me out many times!

    Cheers, Lee.

  • Michael Lawrence 128 posts 200 karma points
    Jul 16, 2010 @ 19:03
    Michael Lawrence
    0

    Haha, yeah, it's an easy thing to overlook! :)

Please Sign in or register to post replies

Write your reply to:

Draft