XSLT 2.0 - Merging adjacent OL elements - xslt-2.0

I'm trying to merge adjacent <ol>|<ul> elements that appear inside <li> elements without success.
Therefore turning:
<ol>
<li>Text node <p>Child node</p>
<ol>
<li>1</li>
</ol>
<ol>
<li>2</li>
<li>3</li>
<li>4</li>
</ol>
<p>Some text</p>
<ol>
<li>1</li>
</ol>
</li>
</ol>
Into
<ol>
<li>Text node <p>Child node</p>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ol>
<p>Some text</p>
<ol>
<li>1</li>
</ol>
</li>
</ol>
Right now, I've come up with this:
<xsl:template match="li[ol]" priority="5">
<xsl:copy copy-namespaces="no">
<ol>
<xsl:for-each-group select="node()" group-adjacent="boolean(self::ol)">
<xsl:choose>
<xsl:when test="current-grouping-key() and current-group()[self::*]">
<xsl:apply-templates select="current-group()/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</ol>
</xsl:copy>
</xsl:template>
Which gives me:
<ol>
<li>
<ol>Text node <p>Child node</p>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<p>Some text</p>
<li>1</li>
</ol>
</li>
</ol>
So I'm struggling to not move the parent <li>'s text into the merged <ol>, how do I fix this?

Using
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="li[ol]">
<xsl:copy>
<xsl:for-each-group select="node()"
group-adjacent="boolean(self::ol | self::text()[not(normalize-space())])">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<ol>
<xsl:copy-of select="current-group()/node()"/>
</ol>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
you can transform
<ol>
<li>Text node <p>Child node</p>
<ol>
<li>1</li>
</ol>
<ol>
<li>2</li>
<li>3</li>
<li>4</li>
</ol>
<p>Some text</p>
<ol>
<li>1</li>
</ol>
</li>
</ol>
into
<ol>
<li>Text node <p>Child node</p>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ol>
<p>Some text</p>
<ol>
<li>1</li>
</ol>
</li>
</ol>

Related

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.

xslt: How do I wrap different tags with new tags

I'm not sure this is even doable with xslt, but here goes.
I need to break the xml from articles into different parts.
I need to get all xml until the first div with class name full-width and wrap that in a div with class name narrow-wrap.
The full-width div needs to be wrapped with a div with class name wide-wrap.
Then a new div with class narrow-wrap starts and all xml until the next div with class full-width goes into that. And so on.
This is a simplified version of the xml. Tags can have nested content, as well as attributes.
<p>lorem</p>
<div>ipsum</div>
<div class="full-width">
<img src="image.jpg" />
</div>
<p>lorem</p>
<p>ipsum</p>
<div class="full-width">
<img src="image.jpg" />
</div>
<div class="narrow-width">
<img src="image.jpg" />
</div>
<p>lorem</p>
<div class="full-width">
<img src="image.jpg" />
</div>
<div class="full-width">
<img src="image.jpg" />
</div>
<table>ipsum</table>
<p>lorem</p>
<p>ipsum</p>
<div class="narrow-width">
<img src="image.jpg" />
</div>
This is how I need it to look like after transformation:
<div class="narrow-wrap">
<p>lorem</p>
<div>ipsum</div>
</div>
<div class="wide-wrap">
<div class="full-width">
<img src="image.jpg" />
</div>
</div>
<div class="narrow-wrap">
<p>lorem</p>
<p>ipsum</p>
</div>
<div class="wide-wrap">
<div class="full-width">
<img src="image.jpg" />
</div>
</div>
<div class="wide-wrap">
<div class="narrow-width">
<img src="image.jpg" />
</div>
</div>
<div class="narrow-wrap">
<p>lorem</p>
</div>
<div class="wide-wrap">
<div class="full-width">
<img src="image.jpg" />
</div>
</div>
<div class="wide-wrap">
<div class="full-width">
<img src="image.jpg" />
</div>
</div>
<div class="narrow-wrap">
<table>ipsum</table>
<p>lorem</p>
<p>ipsum</p>
<div class="narrow-width">
<img src="image.jpg" />
</div>
</div>
The xsl for the full-width part would be something like this:
<xsl:template match="div[contains(concat(' ', #class, ' '), ' full-width ')]">
<div>
<xsl:attribute name="class">
wide-wrap
</xsl:attribute>
<xsl:copy-of select="."></xsl:copy-of>
</div>
</xsl:template>
The part of wrapping all the other content in blocks of divs with class narrow-wrap is beyond me though.
Is this possible, and if so, how?
See the group-adjacent example in https://www.w3.org/TR/xslt20/#grouping-examples and try <xsl:for-each-group select="*" group-adjacent="not (#class = 'full-width')">, then, as in the example check the key and wrap the current-group () respectively each item in the group.
Using that approach you get
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="body">
<xsl:copy>
<xsl:for-each-group select="*" group-adjacent="not (#class = 'full-width')">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<div class="narrow-wrap">
<xsl:apply-templates select="current-group()"/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="div[contains(concat(' ', #class, ' '), ' full-width ')]">
<div class="wide-wrap">
<xsl:copy-of select="."></xsl:copy-of>
</div>
</xsl:template>
</xsl:transform>
online at http://xsltransform.net/6rewNxQ.

making a non logic flat structure hierarchical

I want to group by headers, but when the structure isn't logical the sectioning stops. For example <h2> followed by <h4>. See example. I would like to see the <h4> sectioned when there is no <h3> but I can't seem to get it work. Could someone help me with that? I work with xslt 2.0.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<document id="21" state="Schrijven" documentTypeName="News">
<document track-changes="false" version="1">
<section>
<h1>Title h1</h1>
<p>Some text</p>
<p/>
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<h3>Title h3</h3>
<p>Some text</p>
<p/>
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<h4>Title h4</h4>
<p>Some text</p>
<p/>
</section>
</document>
</document>
Output
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body data-sws-documentkey="id-00021">
<section class="level-newsitem">
<h1 class="nieuws">Title h1</h1>
<p>Some text</p>
<p/>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<section class="level">
<h3>Title h3</h3>
<p>Some text</p>
<p/>
</section>
</section>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<h4>Title h4</h4>
<p>Some text</p>
<p/>
</section>
</section>
</body>
</html>
Desired Output
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body data-sws-documentkey="id-00021">
<section class="level-newsitem">
<h1 class="nieuws">Title h1</h1>
<p>Some text</p>
<p/>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<section class="level">
<h3>Title h3</h3>
<p>Some text</p>
<p/>
</section>
</section>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<section class="level">
<h4>Title h4</h4>
<p>Some text</p>
<p/>
</section>
</section>
</section>
</body>
</html>
Stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cwc="urn:cwc"
xmlns:p1="urn:p1"
exclude-result-prefixes="xs cwc p1"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="document meta section div row"/>
<xsl:variable name="DocumentKey">
<xsl:value-of select="concat('id-000', /document[1]/#id)"/>
</xsl:variable>
<xsl:variable name="DocSoort">
<xsl:value-of select="/document/#documentTypeName"/>
</xsl:variable>
<xsl:template match="document">
<html>
<head>
<meta charset="UTF-8"/>
<xsl:if test="./meta/description">
<meta name="description">
<xsl:attribute name="content">
<xsl:value-of select="./meta/description"/>
</xsl:attribute>
</meta>
</xsl:if>
<title><xsl:value-of select="./naam"/></title>
</head>
<body data-sws-documentkey="{$DocumentKey}">
<xsl:choose>
<xsl:when test="$DocSoort='Note'">
<xsl:apply-templates mode="Note"/>
</xsl:when>
<xsl:when test="$DocSoort='News'">
<xsl:apply-templates mode="News"/></xsl:when>
</xsl:choose>
</body>
</html>
</xsl:template>
<xsl:template match="h1" mode="#all">
<xsl:variable name="DocSoorttitel">
<xsl:choose>
<xsl:when test="$DocSoort='Note'">noteitem</xsl:when>
<xsl:when test="$DocSoort='News'">newsitem</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="count">
<xsl:value-of select="count(preceding::h1)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count = 0">
<xsl:copy>
<xsl:attribute name="class">
<xsl:value-of select="$DocSoorttitel"/>
</xsl:attribute>
<xsl:apply-templates select="#*[name()!='class']" mode="#current"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="#*" mode="#current"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="naam|meta|lastmodified" mode="#all"/>
<xsl:template match="*/document" mode="#all">
<xsl:choose>
<xsl:when test="not(./section)">
<section>
<xsl:attribute name="class">
<xsl:value-of select="lower-case(concat('sws-', $DocSoort))"/>
</xsl:attribute>
<xsl:call-template name="groupingheaders"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="section" mode="#all">
<section>
<xsl:attribute name="class">
<xsl:value-of select="lower-case(concat('level-', $DocSoort))"/>
</xsl:attribute>
<xsl:call-template name="groupingheaders"/>
</section>
</xsl:template>
<xsl:template name="groupingheaders">
<xsl:choose>
<xsl:when test="$DocSoort='Note'">
<xsl:for-each-group select="*" group-starting-with="div[#class = 'letop'][parent::document or parent::section]|h2[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::div[#class = 'letop'][parent::document or parent::section]|current-group()[1]/self::h2[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:call-template name="group2"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:when>
<xsl:when test="$DocSoort='News'">
<xsl:for-each-group select="*" group-starting-with="h2[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::h2[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:call-template name="group2"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="group2">
<xsl:for-each-group select="current-group()" group-starting-with="h3[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::h3[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:call-template name="group3"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="group3">
<xsl:for-each-group select="current-group()" group-starting-with="h4[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::h4[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:call-template name="group4"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="group4">
<xsl:for-each-group select="current-group()" group-starting-with="h5[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::h5[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:call-template name="group5"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="group5">
<xsl:for-each-group select="current-group()" group-starting-with="h6[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<xsl:choose>
<xsl:when test="current-group()[1]/self::h6[parent::document or parent::section][count(text()[normalize-space()]) > 0]">
<section class="level">
<xsl:apply-templates select="current-group()" mode="#current"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node()" mode="#current"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
A regular grouping can be done with a recursive function:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="xs mf"
version="2.0">
<xsl:output method="html" indent="yes"/>
<xsl:param name="prefix" as="xs:string" select="'h'"/>
<xsl:param name="max-level" as="xs:integer" select="6"/>
<xsl:function name="mf:group" as="node()*">
<xsl:param name="nodes" as="node()*"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:for-each-group select="$nodes" group-starting-with="*[local-name() eq concat($prefix, $level)]">
<xsl:choose>
<xsl:when test="self::*[local-name() eq concat($prefix, $level)]">
<section class="level">
<xsl:apply-templates select="."/>
<xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
</section>
</xsl:when>
<xsl:when test="$level lt $max-level">
<xsl:sequence select="mf:group(current-group(), $level + 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[h1 | h2 | h3 | h4 | h5 | h6]">
<xsl:copy>
<xsl:sequence select="mf:group(*, 1)"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
That transforms
<document id="21" state="Schrijven" documentTypeName="News">
<document track-changes="false" version="1">
<section>
<h1>Title h1</h1>
<p>Some text</p>
<p/>
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<h3>Title h3</h3>
<p>Some text</p>
<p/>
<h2>Title h2</h2>
<p>Some text</p>
<p/>
<h4>Title h4</h4>
<p>Some text</p>
<p/>
</section>
</document>
</document>
into
<document id="21" state="Schrijven" documentTypeName="News">
<document track-changes="false" version="1">
<section>
<section class="level">
<h1>Title h1</h1>
<p>Some text</p>
<p></p>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p></p>
<section class="level">
<h3>Title h3</h3>
<p>Some text</p>
<p></p>
</section>
</section>
<section class="level">
<h2>Title h2</h2>
<p>Some text</p>
<p></p>
<section class="level">
<h4>Title h4</h4>
<p>Some text</p>
<p></p>
</section>
</section>
</section>
</section>
</document>
</document>
You need to add your templates for the other elements and maybe, if the first level needs special treatment, extend the function with some conditional checks or write a template or function for the first level.

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,

Resources