Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my solution, with hopefully helpful comments. It works with your example but you may have more specific requirements this doesn't take into account. Still, I hope it will be useful to you.</p> <p>The following XSLT stylesheet:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="html"/&gt; &lt;xsl:param name="id" select="'id:144016'"&gt;&lt;/xsl:param&gt; &lt;xsl:param name="query_string" select="'year=2012&amp;amp;month=12'"/&gt; &lt;!-- Match the siteMapNode element at depth 1 with the specified id. Just apply templates to its children. --&gt; &lt;xsl:template match="siteMapNode[@id=$id and @depth='1']" priority="5"&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:template&gt; &lt;!-- Match the siteMapNode element with the specified id that partially match the query string. These will have child elements so apply templates and keep going. --&gt; &lt;xsl:template match="siteMapNode[@id=$id and contains($query_string, @query_string)]" priority="1"&gt; &lt;li class="active"&gt; &lt;xsl:call-template name="anchor"/&gt; &lt;ul&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;!-- Match the siteMapNode element with the specified id that completely match the query string. --&gt; &lt;xsl:template match="siteMapNode[@id=$id and $query_string=@query_string]" priority="10"&gt; &lt;li class="active icon-nav-left"&gt; &lt;xsl:call-template name="anchor"/&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;!-- Match the remaining siteMapNode elements with the specified id. This template has the default priority of 0.5. --&gt; &lt;xsl:template match="siteMapNode[@id=$id]"&gt; &lt;li&gt; &lt;xsl:call-template name="anchor"/&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;!-- The anchor element we output is common, so put it into a template we can call. --&gt; &lt;xsl:template name="anchor"&gt; &lt;a href="{@url}"&gt; &lt;xsl:value-of select="@title"/&gt; &lt;/a&gt; &lt;/xsl:template&gt; &lt;!-- The built-in template for elements and the root node is already doing what we want, so we don't need to include it explicitly. It's below, commented out, for reference. --&gt; &lt;!-- &lt;xsl:template match="*|/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt;--&gt; &lt;!-- Don't want to output text or attribute nodes unless we explicitly say so, so we need to override the built-in templates for these. --&gt; &lt;xsl:template match="text()|@*"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>gives the following output when applied to your example input XML:</p> <pre><code>&lt;li class="active"&gt;&lt;a href="news-press/newslisting.jsp?year=2012"&gt;2012 Archive&lt;/a&gt;&lt;ul&gt; &lt;li class="active icon-nav-left"&gt;&lt;a href="news-press/newslisting.jsp?year=2012&amp;amp;month=12"&gt;December&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="news-press/newslisting.jsp?year=2012&amp;amp;month=4"&gt;April&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="news-press/newslisting.jsp"&gt;2013 Archive&lt;/a&gt;&lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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