Not able to render child Node's, child Node using Umbraco XSLT - umbraco

I have following Content structure
=Main Home Node
-Child Node 1
-Child Node 2
-Child Node 3
- - Sub Node 1 of Child 3
- - Sub Node 2 of Child 3
- - Sub Node 1 of Child 3
-Child Node 4
I am rendering contains of Child Node which is Richtext Editor(Name = sectionBody)
,As following XSLT code to Render Child Node's.
<xsl:for-each select="$currentPage/ancestor-or-self::* [#level=$level]/* [#isDoc and string(umbracoNaviHide) != '1']">
<h2 class="section-title text-center wow fadeInDown"><xsl:value-of select="sectionHeading"/></h2>
<div class="row">
<xsl:value-of select="umbraco.library:Item($currentPage/#id,'sectionBody')" />
</xsl:for-each>
</div>
</xsl:for-each>
Now I am calling macro in Richtext Editor of Child Node 3 for Rendering contains of Sub Node of child Node 3
Following is XSLT macro code which I am using to render in Richtext Editro
<xsl:variable name="items" select="$currentPage/ancestor-or-self::* [#isDoc and #level = 2 ]/* [#isDoc and string(umbracoNaviHide) != '1']"/>
<div > Sub Node </div>
<xsl:if test="count($items) > 0">
<xsl:for-each select="$items">
<xsl:if test="string-length($items/profileType) > 0">
<div> In If of Sub Node</div>
<xsl:variable name="Chkitems" select="umbraco.library:
Split($items/profileType,',')" />
<xsl:value-of select="$Chkitems"/>
<xsl:for-each select="$Chkitems//value">
<xsl:value-of select="current()"/>
</xsl:for-each>
</xsl:attribute>
</xsl:if>
</xsl:for-each>
</xsl:if>
I am able preview out come of above macro rendering in Richtext Editor.
But while render on the site, Its only show "Sub Node". but not the value of or inner div.
Where I am able to get value of Header "sectionHeading" but can not able to view "sectionBody"

Related

How Can remove 'italic' element inside the 'pub-id', 'italic' element not allowed inside the 'pub-id'

Input:
<DOINUM>10.1080/14772019.2016.1274343</DOINUM>
Output:
No needed 'italic' element inside the 'pub-id' element
<pub-id pub-id-type="doi"><italic>10.1080/14772019.2016.1274343</italic></pub-id>
Xslt Code:
we creat 'pub-id' element below code
<pub-id pub-id-type="doi">
<xsl:apply-templates/>
</pub-id>
we create 'italic' element here, but 'italic' element not allowed inside the 'pub-id element, please give suggestion how can remove 'italic' element inside the 'pub-id' element.
<xsl:template match="IT" mode="demote">
<xsl:param name="content"/>
<xsl:apply-templates select=".." mode="demote">
<xsl:with-param name="content">
<xsl:choose>
<xsl:when test="normalize-space($content)">
<!-- providing 'italic' only if there's something
to put into italics -->
<italic>
<xsl:copy-of select="$content"/>
</italic>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$content"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>

How to group by the elements in XSL

I have an HTML of the following process.
<p class="Ahead">FIRST SECTION</p>
<p class="Text">with a moisture content of 16.34</p>
<p class="Ahead">SECOND SECTION</p>
<p class="Bhead">Second First Section</p>
<p class="Text">with a moisture content of 20.56</p>
<p class="Chead">Second first first section</p>
<p class="Text">with a moisture content of 48.15</p>
The Ahead, Bhead and Chead should be individual group. How it is possible to group it.
The output should be follow below.
<sec>
<title>FIRST SECTION</title>
<p class="Text">with a moisture content of 16.34</p>
</sec>
<sec>
<title>SECOND SECTION</title>
<sec
<title>Second First Section</title>
<p class="Text">with a moisture content of 20.56</p>
<sec>
<title>Second first first section</title>
<p class="Text">with a moisture content of 48.15</p>
</sec>
</sec>
</sec>
Thanks in advance.
Something like this:
<xsl:function name="f:group">
<xsl:param name="level" as="xs:integer"/>
<xsl:param name="population" as="element()*"/>
<xsl:variable name="name" select="('Ahead', 'Bhead', 'Chead')[$level]"/>
<xsl:for-each-group select="$population"
group-starting-with="p[#class=$name]">
<xsl:choose>
<xsl:when test="#class='Text'">
<xsl:copy-of select="current-group()"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="f:group($level+1, current-group())"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
then:
<xsl:template match="/">
<xsl:sequence select="f:group(1, //p)"/>
</xsl:template>
Not tested, just something for you to start with.

ignore the child when using descendant

I've the below XML.
<list>
<list.item>
<label>
<star.page>94</star.page> (a)</label>
</list.item>
<list.item>
<label>(b)</label> As the
</list.item>
</list>
and i was trying to get the maximum string length of label by ignoring child nodes of label, I'm trying to do this using the below.
<xsl:template name="orderedlist" match="list">
<xsl:variable name="strl">
<xsl:value-of select="max(descendant::list.item/label/string-length(text()[fn:not(self::star.page)]))"/>
</xsl:variable>
<xsl:value-of select="$strl"/>
<xsl:choose>
<xsl:when test="$strl > '6'">
<ol class="eng-orderedlist orderedlist1">
<xsl:apply-templates/>
</ol>
</xsl:when>
<xsl:otherwise>
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="orderitem" match="list.item">
<xsl:apply-templates select="./label/node()[1][self::star.page]" mode="first"/>
<li class="item">
<div class="para">
<xsl:if test="./label">
<span class="item-num">
<xsl:value-of select="./label/text()"/>
</span>
</xsl:if>
<xsl:choose>
<xsl:when test="./text()">
<xsl:apply-templates select="child::node()[fn:not(self::label)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</div>
</li>
</xsl:template>
By suggestion of #Martin Honnen, here enter link description here, i tried the below.
but it is giving the below error.
XSLT 2.0 Debugging Error: Error: file:///C:/Users/u0138039/Desktop/Proview/Law%20Reports/HK/11NOV/P1/XML/XSLT/Reports(RXXX_sma-DXXXHX).xslt:1420: Wrong occurrence to match required sequence type - Details: - XPTY0004: The supplied sequence ('2' item(s)) has the wrong occurrence to match the sequence type xs:string ('zero or one')
please let eme know where am i going wrong.
Thanks

How to turn-off showing child items for selected Main Menu items in Umbraco CMS?

In order to explain my issue easier, please first see this photo
On my template I have already configured Top navigation but problem is that I am trying to make new menu Item which will be called 'News' and thing is that I don't want that every out of 99 news items I will publish (in next two months), to be autmatically available as sumbenu child item under 'News'.
As I noticed, most of the configuration is under 'umbTopNavigation.xslt'
]>
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>
<xsl:template match="/">
<ul id="topNavigation">
<li class="home">
<xsl:if test="$currentPage/#id = $currentPage/ancestor-or-self::* [#level=$level]/#id">
<xsl:attribute name="class">home current</xsl:attribute>
</xsl:if>
Home
</li>
<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>
</xsl:template>
but I can't figure out what exactly I need to change?
Any help is appreciated and many thanks in advance!
MC2012
First macro
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="items" select="$currentPage/ancestor-or-self::* [#isDoc and #level = 2]/* [#isDoc and string(umbracoNaviHide) != '1']"/>
<!-- The fun starts here -->
<xsl:if test="count($items) > 0">
<ul>
<xsl:for-each select="$items">
<li>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Second Macro
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="umbraco.library"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Specify level of the top node for a language (usually 1) -->
<xsl:variable name="level" select="1" />
<!-- Grab the top node -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[#level = $level]" />
<xsl:template match="/">
<ul class="menu">
<!-- Create the Home link -->
<li>
<xsl:if test="$currentPage/#id = $siteRoot/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl($siteRoot/#id)}">
<xsl:value-of select="$siteRoot/#nodeName" />
</a>
</li>
<!-- Process all children of $siteRoot (if any) -->
<xsl:apply-templates select="$siteRoot/*[#isDoc][not(umbracoNaviHide = 1)]" />
</ul>
</xsl:template>
<!-- Generic template for all nav links -->
<xsl:template match="*[#isDoc]">
<li>
<xsl:if test="#id = $currentPage/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName" />
</a>
<!-- Render sub menu if necessary -->
<xsl:call-template name="submenu" />
</li>
</xsl:template>
<!-- Template for Inactive links -->
<xsl:template match="*[#isDoc][umbracoNaviInactive = 1]">
<li>
<xsl:if test="#id = $currentPage/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<span>
<xsl:value-of select="#nodeName" />
</span>
<!-- Submenu? -->
<xsl:call-template name="submenu" />
</li>
</xsl:template>
<!-- Template checking for, and processing any submenu -->
<xsl:template name="submenu">
<xsl:variable name="subPages" select="*[#isDoc][not(umbracoNaviHide = 1)]" />
<xsl:if test="$subPages">
<ul>
<xsl:apply-templates select="$subPages" />
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Ok - you have two options. A quick hack or a full solution.
The quick hack is to update the second macro where the subnav is called and exclude the subnav being called where it's the news page (and you can include other pages in here too)
In this example I've used node ID 1107 to be the ID of your news page, but you will need to update this with your actual news page ID.
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="umbraco.library"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Specify level of the top node for a language (usually 1) -->
<xsl:variable name="level" select="1" />
<!-- Grab the top node -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[#level = $level]" />
<xsl:template match="/">
<ul class="menu">
<!-- Create the Home link -->
<li>
<xsl:if test="$currentPage/#id = $siteRoot/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl($siteRoot/#id)}">
<xsl:value-of select="$siteRoot/#nodeName" />
</a>
</li>
<!-- Process all children of $siteRoot (if any) -->
<xsl:apply-templates select="$siteRoot/*[#isDoc][not(umbracoNaviHide = 1)]" />
</ul>
</xsl:template>
<!-- Generic template for all nav links -->
<xsl:template match="*[#isDoc]">
<li>
<xsl:if test="#id = $currentPage/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName" />
</a>
<!-- Render sub menu if necessary excluding the news pages -->
<xsl:if test="not(#id=1107)">
<xsl:call-template name="submenu" />
</xsl:if>
</li>
</xsl:template>
<!-- Template for Inactive links -->
<xsl:template match="*[#isDoc][umbracoNaviInactive = 1]">
<li>
<xsl:if test="#id = $currentPage/#id">
<xsl:attribute name="class">sel</xsl:attribute>
</xsl:if>
<span>
<xsl:value-of select="#nodeName" />
</span>
<!-- Submenu? -->
<xsl:call-template name="submenu" />
</li>
</xsl:template>
<!-- Template checking for, and processing any submenu -->
<xsl:template name="submenu">
<xsl:variable name="subPages" select="*[#isDoc][not(umbracoNaviHide = 1)]" />
<xsl:if test="$subPages">
<ul>
<xsl:apply-templates select="$subPages" />
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The proper way to do it would be to add a property to your document type to include a property to say do not list children or similar, and then test for that in the XSLT, but that's a much more involved fix, and for that I suggest you read up a bit more on how XSLTs work. Let me know if you want to go down that route and there are plenty of resources I can direct you to
thanks,

How to Create a Filtered DataView on a Joined Data Source in SharePoint Designer 2007

I am trying to create a filtered DataView for MOSS 2007 using SharePoint Designer 2007. The following simplified example demonstrates what I am trying to accomplish.
Suppose I have two lists: Colors and People. The list of people has a lookup column called Favorite Color that allows the user to select from the list of colors.
I want to create a DataView that will only display the colors that nobody has selected as their favorite color.
I have successfully created a DataView that shows each color and the number of people who have chosen that color by inserting the following XSL code:
<xsl:value-of select="count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = current()/#Title])" />
I tried to apply to same logic to the DataView query as shown below, but this still returned all the rows:
<xsl:variable name="Rows" select="/dsQueryResponse/Colors/Rows/Row[count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = current()/#Title]) = 0]"/>
I think the problem with the above is that at the time the query takes place, the current() function doesn't work because there isn't a current row. So I also tried using a complete reference, which yielded the same results:
<xsl:variable name="Rows" select="/dsQueryResponse/Colors/Rows/Row[count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = dsQueryResponse/Colors/Rows/Row/#Title]) = 0]"/>
Is it possible to do the type of query I want using XSL? If so, where have I gone wrong? The complete XSL is given below:
<XSL><xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Colors/Rows/Row[count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = dsQueryResponse/Colors/Rows/Row/#Title]) = 0]"/>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="nowrap">Color</th>
<th class="ms-vh" nowrap="nowrap">Number of People</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<xsl:value-of select="#Title"/>
</td>
<td class="ms-vb">
<xsl:value-of select="count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = current()/#Title])" />
</td>
</tr>
</xsl:template>
I haven't actually tried this but what if you do basically what Andrew suggests, looping through the Colors list first. Just don't display the row if the criteria isn't met.
<xsl:variable name="Rows" select="/dsQueryResponse/Colors/Rows/Row"/>
and then
<xsl:template name="dvt_1.rowview">
<xsl:variable name="title" select="#Title" />
<xsl:if test="count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = $title]) > 0">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<xsl:value-of select="#Title"/>
</td>
<td class="ms-vb">
<xsl:value-of select="count(/dsQueryResponse/People/Rows/Row[#Favorite_x0020_Color = $title])" />
</td>
</tr>
</xsl:if>
</xsl:template>

Resources