Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Jun 10, 2014 @ 11:10
    Bex
    0

    what syntax do I need to get my nodes in custom xml?

    Hi

    I am trying to generate a custom site map that contains custom pages not stored in umbraco. I have xml with a structure like this:

    <pages>
      <page>
       <id>1</id>
       <name>name 1</name>
       <friendlyurl>http://www.website.com?pages=1</friendlyurl>;
      </page>
      <page>
       <id>2</id>
       <name>name 2</name>
       <friendlyurl>http://www.website.com?pages=2</friendlyurl>;
      </page>
    

    this is xml generated in c# and accessed via an extension. I need to loop the pages and create my site map.

    So far I have this XSLT

    <xsl:for-each select="CustomExt:GetCustomPages()">
          <url>
          <loc>            
            <xsl:value-of select="@FriendlyUrl" />
          </loc>
          <lastmod>
           //get later
          </lastmod>
          <changefreq>
            weekly
          </changefreq>
          <priority>
            0.5
          </priority>
        </url>    
    </xsl:for-each>
    

    What do I need to have in my selects to actually get the friendlyurl? I have tried doing a different select in the for each

    <xsl:for-each select="CustomExt:GetCustomPages()/pages/page">
    

    or <xsl:value-of select="@page" />

    I know my syntax is wrong, but I cant work out what syntax I need!

    can anyone help?

    Bex

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 10, 2014 @ 11:23
    Chriztian Steinmeier
    0

    Hi Bex,

    How does your C# extension return the document? Usually an extension returns something like this:

    return xmldoc.Select("/");
    

    and then you need to do this in the XSLT:

    <xsl:variable name="pages" select="CustomExt:GetCustomPages()/pages" />
    
    <xsl:for-each select="$pages/page">
        <url>
      <loc>            
        <xsl:value-of select="friendlyurl" />
      </loc>
      <lastmod>
       //get later
      </lastmod>
      <changefreq>
        weekly
      </changefreq>
      <priority>
        0.5
      </priority>
    </url>
    </xsl:for-each>
    

    Hope that helps - basically, the root node of your document is the slash and below that the root element (i.e. your <pages> element).

    You select the elements by using the name they have in the XML - which is case-sensitive, by the way.

    /Chriztian

  • Bex 444 posts 555 karma points
    Jun 10, 2014 @ 11:29
    Bex
    0

    Hi Chriztian

    Thanks for the quick respons!

    I am returning it as an XPathNavigator. When I do a

    <xsl:copy-of select="CustomExt:GetCustomPages()"/>
    

    I see all my xml but am I returning the wrong type?

    I can return a nodelist by doing

    doc.SelectNodes("/") 
    

    as its an XmlDocument, would this be better?

  • Bex 444 posts 555 karma points
    Jun 10, 2014 @ 11:46
    Bex
    0

    I have tried returning the nodelist but its not a valid type! I have also tried returning a string but that so far isn't working.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 10, 2014 @ 13:08
    Chriztian Steinmeier
    100

    Hi Bex,

    XPathNavigator should be fine - I think you're just experiencing case-issues...

    Are you doing the copy-of inside the XSLT Visualizer in Umbraco? If so, you need to wrap it inside a <textarea> because the visualizer lowercases everything, e.g.:

    <textarea cols="50" rows="20">
        <xsl:copy-of select="CustomExt:GetCustomPages()" />
    </textarea>
    

    XML is case-sensitive (and thus XSLT is too) so you need to use the correct casing when referring to the elements in the XML.

    /Chriztian

  • Bex 444 posts 555 karma points
    Jun 10, 2014 @ 13:42
    Bex
    0

    ..and that's what the problem was! :) thank you!

Please Sign in or register to post replies

Write your reply to:

Draft