Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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" />
<xsl:value-of select="@page" />
I know my syntax is wrong, but I cant work out what syntax I need!
can anyone help?
Bex
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).
<pages>
You select the elements by using the name they have in the XML - which is case-sensitive, by the way.
/Chriztian
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?
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.
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>
<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.
..and that's what the problem was! :) thank you!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
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
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
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
Hi Bex,
How does your C# extension return the document? Usually an extension returns something like this:
and then you need to do this in the XSLT:
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
Hi Chriztian
Thanks for the quick respons!
I am returning it as an XPathNavigator. When I do a
I see all my xml but am I returning the wrong type?
I can return a nodelist by doing
as its an XmlDocument, would this be better?
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.
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.: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
..and that's what the problem was! :) thank you!
is working on a reply...