Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" exclude-result-prefixes="x"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:key name="kaByTail" match="x:a" use="substring-after(@title, ' ')"/&gt; &lt;xsl:key name="kaByHeadAndTail" match="x:a" use="concat(substring-before(@title, ' '), '+', substring-after(@title, ' ') )"/&gt; &lt;xsl:variable name="vAncors" select="//x:a"/&gt; &lt;xsl:template match="/"&gt; &lt;root&gt; &lt;element title="hard-coded title" href="hard-coded url"&gt; &lt;xsl:for-each select= "$vAncors [generate-id() = generate-id(key('kaByTail', substring-after(@title, ' ') ) [1] ) ]"&gt; &lt;xsl:variable name="vKey" select="substring-after(@title, ' ')"/&gt; &lt;xsl:variable name="vGroup" select= "key('kaByTail', $vKey)"/&gt; &lt;element title="{$vKey}" href="{$vKey}.html"&gt; &lt;xsl:for-each select= "$vGroup [generate-id() = generate-id(key('kaByHeadAndTail', concat(substring-before(@title, ' '), '+', $vKey ) ) [1] ) ] "&gt; &lt;xsl:variable name="vKey2" select="substring-before(@title, ' ')"/&gt; &lt;xsl:element name="{$vKey2}"&gt; &lt;xsl:for-each select= "key('kaByHeadAndTail', concat($vKey2,'+',$vKey) )"&gt; &lt;xsl:sort/&gt; &lt;element title="{.}" href="{@href}"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/element&gt; &lt;/xsl:for-each&gt; &lt;/element&gt; &lt;/root&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document</strong>:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en"&gt; &lt;head&gt; &lt;title&gt;HTML Document Title&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Welcome&lt;/h1&gt; &lt;div class="container"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="a.html" title="abcdef AAA"&gt;New York&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="b.html" title="abcdef AAA"&gt;Los Angles&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="c.html" title="abcdef AAA"&gt;Alaska&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="d.html" title="abcdef BBB"&gt;Florida&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="e.html" title="zyxwvu AAA"&gt;&lt;em&gt;California&lt;/em&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;root&gt; &lt;element title="hard-coded title" href="hard-coded url"&gt; &lt;element title="AAA" href="AAA.html"&gt; &lt;abcdef&gt; &lt;element title="Alaska" href="c.html"/&gt; &lt;element title="Los Angles" href="b.html"/&gt; &lt;element title="New York" href="a.html"/&gt; &lt;/abcdef&gt; &lt;zyxwvu&gt; &lt;element title="California" href="e.html"/&gt; &lt;/zyxwvu&gt; &lt;/element&gt; &lt;element title="BBB" href="BBB.html"&gt; &lt;abcdef&gt; &lt;element title="Florida" href="d.html"/&gt; &lt;/abcdef&gt; &lt;/element&gt; &lt;/element&gt; &lt;/root&gt; </code></pre> <p><strong>Explanation</strong>: Nested Muenchian grouping using first a single, then a composite grouping key.key</p>
    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.
 

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