How to code Umbraco XSLT to retrieve Nodes from unrelated tree - xslt

I have an Umbraco site for personal use that I want to also use as a blog.
I'm trying to put together the XSLT to grab the top three posts from the nodes in the Blog tree (node id = 1063) and display these on a tab page that is incorporated into the front page.
The following image illustrates the node hierarchy:
With my extremely limited appreciation of XSLT, I'm unable to grab the node ID of the "Blog" id and take the 3 pages below that to display in the "Top Posts" part of my site which is found under the "Frontpage Tabs" node. All the examples I find work with the "current page", which is typically the top-level node, "Personal Site".
How should I accomplish this?
EDIT
The rendered output is actually blank on the published page (even after republishing the entire site) but the preview displayed in the back office rich text editor for the "Top Posts" tab content is displayed correctly.
The XSLT I'm using looks like this:
<xsl:template match="/">
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById(1063)/umbBlogPost [#isDoc]">
<li><xsl:value-of select="#nodeName"/></li>
</xsl:for-each>
</ul>
</xsl:template>
The HTML shown in the tab's Rich Text Editor looks like this:
<div umb_macroalias="Dn.BlogListTopThreePosts" ismacro="true" onresizestart="return false;" umbversionid="cb1efb8d-f58c-424b-9c12-df14ac5652d9" umbpageid="1115" title="This is rendered content from macro" class="umbMacroHolder"><!-- startUmbMacro -->
<ul>
<li>Test Post</li>
</ul>
<!-- endUmbMacro --></div>
I'll update this post again once I've retrieved the XML from the Database (if that's helpful). The issue is less the actual data as it is the disconnect between the published page and the back end.

I've not tested this (I don't have your data), but use the position() method to stop processing after a set number of iterations (some good xslt examples here).
<xsl:variable name="blogRoot" select="1063"/>
<xsl:for-each select="umbraco.library:GetXmlNodeById($blogRoot)/umbBlogPost [#isDoc]">
<xsl:if test="position() <= 3">
<li><xsl:value-of select="#nodeName"/>
</li>
</xsl:if>
</xsl:for-each>
If you were using razor, you could do something like:
#using uComponents.Core;
#using uComponents.Core.uQueryExtensions;
#{
var topThreeBlogPosts = #uQuery.GetNodesByType(<blog post doc type>).Take(3);
foreach(blogItem in topThreeBlogPosts)
{
<li>#blogItem.nodeName</li>
}
}

Related

xsl how to direct the html content to xml content through clicking on the html uri link

I have a xml structure like below:
<PAGES>
<PAGE>
<PAGENUMBER>1</PAGENUMBER>
<SECTION>
<SECTIONITEM>
<ITEMNUMBER>1</ITEMNUMBER>
<TITLE>Interactive Forms</TITLE>
<TOPIC>
<SUBTITLE>Intro to Forms & Attributes </SUBTITLE>
<ITEM>1</ITEM>
<PARA>This is the explanation for Topic ITEM 1</PARA>
<GRAPH>This the the link to the GRAPHIC</GRAPH>
</TOPIC>
</SECTIONITEM>
</SECTION>
</PAGE>
....<!-- lots of page blocks-->
</PAGES>
Now I have to generate a html summary that will list the PAGENUMBERs when certain conditions are satisfied and generate an <a href> link for the PAGENUMBER in the html. The request is that when user clicks on the page number link on the html, xml file will be popped up and directed to the related xml content.
Is this possible to link PAGENUMBER to the related xml content using xsl? I don't have enough experience to do this now.
Could anybody give me some suggestion or this could be done using other language like java or javascript?
Many thanks in advance!

Insert element in a tag on the fly (all in the "content" side)

I need to modify on-the-fly the "content" side of a tag appending some text.
I have (on the content side) the classic portal-tabs:
<ul class="nav" id="portal-globalnav">
....
<li id="portaltab-events" class="plain">
Eventi
</li>
</ul>
I need to append (via diazo) on-the fly the content of another tag (#numbers) to obtain something like:
<ul class="nav" id="portal-globalnav">
....
<li id="portaltab-events" class="plain">
Eventi
<div id="#numbers">33</div>
</li>
</ul>
How solve this issue?
Thank's
You might see if this helps: http://docs.diazo.org/en/latest/recipes/modifying-text/index.html
Also, where does the #numbers div come from? If you append it to each LI tag, you'll have an invalid HTML (more than one element with the same ID)
A content replace containing a little XSL should do it.
<replace css:content="#portaltab-events a">
<xsl:copy-of select="." />
<xsl:copy-of select="//*[#id='numbers']" />
<xsl:apply-templates />
</replace>
If you separately drop the #numbers div, you'll need to add mode="raw" to the apply-templates to prevent it from being dropped here.

Unique Name for Navigation Item in Umbraco

I am using the default umbTopNavigation.xslt file and would like to have different navigation menu item names from the URLs. Currently, whatever I name the page in the Content Editor determines the URL of that page, (ie. About Us = about-us.aspx). But what if I want the menu item to read "About Us" but the URL be "about.aspx" ? I added a textstring to the doctype with the id "menuItemName" but I am not sure what the proper syntax is to edit this code to have that in it:
<ul id="topNavigation" class="nav">
<xsl:for-each select="$currentPage/ancestor-or-self::* [#level=$level]/* [#isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:if test="#id = $currentPage/#id">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a class="navigation" href="{umbraco.library:NiceUrl(#id)}">
<span><xsl:value-of select="#nodeName"/></span>
</a>
</li>
</xsl:for-each>
</ul>
Obviously this is the line that needs to be changed:
<span><xsl:value-of select="#nodeName"/></span>
...but I don't know what to?
Okay, I never understood what I was reading when I kept seeing articles about umbracoUrlName, but I finally figured it out.
Basically, I keep the code above the same, but I just changed the alias from menuItemName to umbracoUrlName (it is a textstring) and whatever I put in there is what the URL is for that page!
Geeze, I feel silly now, but at least it is working!

Incremental counter for <li> tags in XSLT

I'm using XSLT to pull some data from child nodes in an Umbraco (4.7) structure. That part is working fine, but I need to style each <li> item slightly different, so each one will be: <li id=x> where x is an integer between 1 and 15.
I've found a couple of methods for incrementing a counter value in XSLT, but I can't tell why it's not working as it should. Here's the relevant source:
<ul>
<xsl:for-each select="$currentPage/Solutions/SolutionsItem[#isDoc]">
<xsl:variable name="count">
<xsl:number/>
</xsl:variable>
<li id="$count">
<a><xsl:value-of select="solutionsItemTitle" /></a>
</li>
</xsl:for-each>
</ul>
When I review the HTML's source after running the XSLT, it just shows <li id=$count> rather than an integer. Can anyone suggest where to go from here?
You need an attribute value template <li id="{$count}">...</li> to compute the attribute value from the XPath expression.

Umbraco : displaying an image using the XSLT

I'm pretty new to umbraco but found the system pretty easy to use and have done alot in a short space of time. One difficulty I have come accross is displaying an image.
In the document type I have added an "upload" where an image is selected.
In my XSLT I loop through the pages, this loop displays the other fields such as description or title. I am trying to display the image here.
Here is my XSLT for displaying my image, this displays nothing. The field "promothumbImage" is defined in the document type, as I said everything else is working fine.
<xsl:value-of select="promothumbImage"/>
Does anyone have any ideas as to where I am going wrong?
EDIT:
promothumbimage is defined in the document of type "upload"
My XSLT:
<!-- The fun starts here -->
<div class="promoitems">
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [#isDoc and
string(umbracoNaviHide) != '1']">
<div class="promoitem">
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName"/>
</a>
<div class="promosmalldesc">
<xsl:value-of select="promoSmallDesc"/>
</div>
<xsl:copy-of select="promothumbImage/*"/>
</div>
</xsl:for-each>
Upload means that the element promothumbImage returns the URL of the image, thus the following should display it on the page:
<img src="{promothumbImage}" alt=""/>
I found the answer, use:
<img src="{promothumImage}" />
to display the image from the "upload" set in the document type
use may simply in your template using your image field throght Media picker Data Type:
<img class="className" src='<umbraco:Item field="infoGraphic" runat="server" Xslt="umbraco.library:GetMedia({0},false())/umbracoFile"/>'/>