Copied to clipboard

Flag this post as spam?

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


  • Craig Palenshus 39 posts 63 karma points
    Apr 21, 2010 @ 07:22
    Craig Palenshus
    0

    xpath to access a parent's sibling node

    I'm trying to show photos (that are attached to documents inside Umbraco) with posts from blogs coming from outside Umbraco.

    I started with xslt created from this post: http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/reading-rss-feeds,-aggregating-and-sorting

    I then added the author's node inside the container which is giving me the following xml:

    <container>
        <?xml-stylesheet type="text/xsl" ....>
        <rss>
            <channel>
                <title>My Blog</title>
                <link>http://myurl.com/</link>;
                <description>My Title</description>
                <item>
                    <title>My Post Title</title>
                    <link>http://myurl.com/myposttitle</link>;
                    <pubDate>Thu, 01 Apr 2010 12:13:00 GMT</pubDate>
                    <description>
                        My Post description
                     </description>
                </item>
            </channel>
        </rss>
        <node id="1200" nodeName="My Name" nodeTypeAlias="teamMember">

            <data alias="teamMemberIcon">/media/18301/my-photo.png</data>   
        </node>
    </container>

    Now that I have everything in the xml, while iterating through the 'container/rss/channel/item's I need to get the teamMemberIcon from the preceeding-sibling of the rss element.

    What is the correct xpath to get this?

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Apr 21, 2010 @ 08:56
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 10:08
    Lee Kelleher
    1

    Hi Craig,

    Try the following XPath:

    <xsl:value-of select="ancestor::rss/following-sibling::node[1]/data[alias='teamMemberIcon']" />

    The idea being that in the for-each of an <item>, you want to navigate up to the <rss> ancestor, then on-to the following <node> (sibling), then drill down into the <data> element.

    Let us know how it works out.

    Cheers, Lee.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 10:10
    Lee Kelleher
    0

    Forgot to mention, there are many ways to navigate using XPath Axes, read more here:

    http://www.w3schools.com/xpath/xpath_axes.asp

  • Craig Palenshus 39 posts 63 karma points
    Apr 22, 2010 @ 04:25
    Craig Palenshus
    1

    That worked great, Lee. Thanks! The only thing I had to change was the data predicate needed the @ symbol.

    data[@alias='teamMemberIcon']
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 22, 2010 @ 10:41
    Lee Kelleher
    0

    Yes, thanks Craig, well spotted. Thats what happens when you write XPath off the top of your head! ;-)

Please Sign in or register to post replies

Write your reply to:

Draft