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"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="book"&gt; &lt;body&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/body&gt; &lt;/xsl:template&gt; &lt;xsl:template match="book/@title"&gt; &lt;h2&gt;&lt;xsl:value-of select="."/&gt;&lt;/h2&gt; &lt;/xsl:template&gt; &lt;xsl:template match="author"&gt; &lt;p&gt;by &lt;xsl:value-of select="name"/&gt;&lt;/p&gt; &lt;h3&gt;Table of Contents&lt;/h3&gt; &lt;ul&gt; &lt;xsl:apply-templates mode="TC" select="following-sibling::*"/&gt; &lt;/ul&gt; &lt;/xsl:template&gt; &lt;xsl:template mode="TC" match="chapter[section]|section[section]"&gt; &lt;li&gt;&lt;xsl:value-of select="@title"/&gt; &lt;ul&gt; &lt;xsl:apply-templates mode="TC"/&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;xsl:template mode="TC" match= "chapter[not(section)]|section[not(section)]"&gt; &lt;li&gt;&lt;xsl:value-of select="@title"/&gt;&lt;/li&gt; &lt;/xsl:template&gt; &lt;xsl:template match="chapter|section"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;book title="D"&gt; &lt;author&gt; &lt;name&gt;abc&lt;/name&gt; &lt;/author&gt; &lt;chapter title="chapter1"&gt; &lt;section title="section1.1"/&gt; &lt;section title="section1.2"&gt; &lt;section title="section1.2.1"/&gt; &lt;section title="section1.2.2"/&gt;&lt;/section&gt; &lt;section title="section3"&gt; &lt;section title="section3.1"/&gt;&lt;/section&gt; &lt;/chapter&gt; &lt;chapter title="chapter2"/&gt; &lt;/book&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;body&gt; &lt;h2&gt;D&lt;/h2&gt; &lt;p&gt;by abc&lt;/p&gt; &lt;h3&gt;Table of Contents&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;chapter1&lt;ul&gt; &lt;li&gt;section1.1&lt;/li&gt; &lt;li&gt;section1.2&lt;ul&gt; &lt;li&gt;section1.2.1&lt;/li&gt; &lt;li&gt;section1.2.2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;section3&lt;ul&gt; &lt;li&gt;section3.1&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;chapter2&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; </code></pre> <p><strong>and it is displayed in the browser as</strong>:</p> <p></p> <h2>D</h2> <p>by abc</p> <h3>Table of Contents</h3> <ul> <li>chapter1<ul> <li>section1.1</li> <li>section1.2<ul> <li>section1.2.1</li> <li>section1.2.2</li> </ul> </li> <li>section3<ul> <li>section3.1</li> </ul> </li> </ul> </li> <li>chapter2</li> </ul> <p></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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