Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT: Select following-sibling until reaching a specified tag
    text
    copied!<p>I am attempting to write XSLT that will run a for-each on the selected following-siblings but stop when another tag (h1) is reached.</p> <p>Here's the Source XML:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;html&gt; &lt;h1&gt;Test&lt;/h1&gt; &lt;p&gt;Test: p 1&lt;/p&gt; &lt;p&gt;Test: p 2&lt;/p&gt; &lt;h1&gt;Test 2&lt;/h1&gt; &lt;p&gt;Test2: p 1&lt;/p&gt; &lt;p&gt;Test2: p 2&lt;/p&gt; &lt;p&gt;Test2: p 3&lt;/p&gt; &lt;/html&gt; </code></pre> <p>Here's the XSLT:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;content&gt; &lt;xsl:apply-templates/&gt; &lt;/content&gt; &lt;/xsl:template&gt; &lt;xsl:template match="h1"&gt; &lt;section&gt; &lt;sectionHeading&gt; &lt;xsl:apply-templates/&gt; &lt;/sectionHeading&gt; &lt;sectionContent&gt; &lt;xsl:for-each select="following-sibling::p"&gt; &lt;paragraph&gt; &lt;xsl:value-of select="."/&gt; &lt;/paragraph&gt; &lt;/xsl:for-each&gt; &lt;/sectionContent&gt; &lt;/section&gt; &lt;/xsl:template&gt; &lt;xsl:template match="p"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Here's the current result:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;content&gt; &lt;section&gt; &lt;sectionHeading&gt;Test&lt;/sectionHeading&gt; &lt;sectionContent&gt; &lt;paragraph&gt;Test: p 1&lt;/paragraph&gt; &lt;paragraph&gt;Test: p 2&lt;/paragraph&gt; &lt;paragraph&gt;Test: p 3&lt;/paragraph&gt; &lt;paragraph&gt;Test2: p 1&lt;/paragraph&gt; &lt;paragraph&gt;Test2: p 2&lt;/paragraph&gt; &lt;/sectionContent&gt; &lt;/section&gt; &lt;section&gt; &lt;sectionHeading&gt;Test 2&lt;/sectionHeading&gt; &lt;sectionContent&gt; &lt;paragraph&gt;Test2: p 1&lt;/paragraph&gt; &lt;paragraph&gt;Test2: p 2&lt;/paragraph&gt; &lt;/sectionContent&gt; &lt;/section&gt; &lt;/content&gt; </code></pre> <p>Here's the expected result:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;content&gt; &lt;section&gt; &lt;sectionHeading&gt;Test&lt;/sectionHeading&gt; &lt;sectionContent&gt; &lt;paragraph&gt;Test: p 1&lt;/paragraph&gt; &lt;paragraph&gt;Test: p 2&lt;/paragraph&gt; &lt;paragraph&gt;Test: p 3&lt;/paragraph&gt; &lt;/sectionContent&gt; &lt;/section&gt; &lt;section&gt; &lt;sectionHeading&gt;Test 2&lt;/sectionHeading&gt; &lt;sectionContent&gt; &lt;paragraph&gt;Test2: p 1&lt;/paragraph&gt; &lt;paragraph&gt;Test2: p 2&lt;/paragraph&gt; &lt;/sectionContent&gt; &lt;/section&gt; &lt;/content&gt; </code></pre>
 

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