Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've created a solution to your problem (and I have heavily modified your approach in the process):</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /&gt; &lt;xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /&gt; &lt;xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'" /&gt; &lt;xsl:variable name="validRange" select="concat($upper, $lower)" /&gt; &lt;xsl:template match="NavigationTree"&gt; &lt;ul class="level1"&gt; &lt;xsl:apply-templates select="Page"&gt; &lt;xsl:sort select="@Sort" data-type="number" /&gt; &lt;/xsl:apply-templates&gt; &lt;/ul&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Page"&gt; &lt;xsl:variable name="idText" select=" translate( translate(@MenuText, translate(@MenuText, $validRange, ''), ''), $upper, $lower ) " /&gt; &lt;li id="{$idText}"&gt; &lt;a href="{@FriendlyHref}" id="anchor-{$idText}"&gt; &lt;xsl:attribute name="class"&gt; &lt;xsl:if test="position() = 1"&gt;firstitem &lt;/xsl:if&gt; &lt;xsl:if test="position() &amp;gt; 1 and position() &amp;lt; last()"&gt;miditem &lt;/xsl:if&gt; &lt;xsl:if test="position() = last()"&gt;lastitem &lt;/xsl:if&gt; &lt;xsl:if test="@InPath='True'"&gt;inpath &lt;/xsl:if&gt; &lt;!-- the descendant-or-self XPath axis solves your question! --&gt; &lt;xsl:if test="descendant-or-self::Page[@Active='True']"&gt;active &lt;/xsl:if&gt; &lt;/xsl:attribute&gt; &lt;span&gt; &lt;xsl:value-of select="@MenuText" /&gt; &lt;/span&gt; &lt;/a&gt; &lt;xsl:if test="Page"&gt; &lt;ul class="level{Page/@AbsoluteLevel}"&gt; &lt;xsl:apply-templates select="Page"&gt; &lt;xsl:sort select="@Sort" data-type="number" /&gt; &lt;/xsl:apply-templates&gt; &lt;/ul&gt; &lt;/xsl:if&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Which results in (when page 20 is set to "active"):</p> <pre><code>&lt;ul class="level1"&gt; &lt;li id="home"&gt; &lt;a href="/default/home.aspx" id="anchor-home" class="firstitem inpath"&gt; &lt;span&gt;Home&lt;/span&gt; &lt;/a&gt; &lt;ul class="level2"&gt; &lt;li id="news"&gt; &lt;a href="/default/home/news.aspx" id="anchor-news" class="firstitem"&gt; &lt;span&gt;News&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li id="about"&gt; &lt;a href="/default/home/about.aspx" id="anchor-about" class="miditem"&gt; &lt;span&gt;About&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li id="presence"&gt; &lt;a href="/default/home/presence.aspx" id="anchor-presence" class="lastitem"&gt; &lt;span&gt;Presence&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="hygiene"&gt; &lt;a href="/default/hygiene.aspx" id="anchor-hygiene" class="miditem"&gt; &lt;span&gt;Hygiene&lt;/span&gt; &lt;/a&gt; &lt;ul class="level2"&gt; &lt;li id="professional"&gt; &lt;a href="/default/hygiene/professional.aspx" id="anchor-professional" class="firstitem"&gt; &lt;span&gt;Professional&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li id="private"&gt; &lt;a href="/default/hygiene/private.aspx" id="anchor-private" class="lastitem"&gt; &lt;span&gt;Private&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="householdleisure"&gt; &lt;a href="/default/household---leisure.aspx" id="anchor-householdleisure" class="miditem"&gt; &lt;span&gt;Household &amp;amp; Leisure&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li id="carcare"&gt; &lt;a href="/default/car-care.aspx" id="anchor-carcare" class="miditem active"&gt; &lt;span&gt;Car Care&lt;/span&gt; &lt;/a&gt; &lt;ul class="level2"&gt; &lt;li id="carix"&gt; &lt;a href="/default/car-care/carix.aspx" id="anchor-carix" class="firstitem lastitem active"&gt; &lt;span&gt;Carix&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="industrialchemicals"&gt; &lt;a href="/default/industrial-chemicals.aspx" id="anchor-industrialchemicals" class="lastitem"&gt; &lt;span&gt;Industrial Chemicals&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Be aware that you do not want <code>disable-output-escaping="yes"</code>, I've removed that since it would produce malformed XML.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload