Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This XSLT 1.0 (and of course, also XSLT 2.0) 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="text()"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:call-template name="Split"&gt; &lt;xsl:with-param name="pSplitters" select="//Br"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="Split"&gt; &lt;xsl:param name="pSplitters"/&gt; &lt;xsl:if test="$pSplitters"&gt; &lt;xsl:for-each select="$pSplitters[1]"&gt; &lt;xsl:call-template name="buildTree"&gt; &lt;xsl:with-param name="pLeafs" select= "preceding-sibling::node()[not(descendant::Br)]"/&gt; &lt;/xsl:call-template&gt; &lt;xsl:if test= "not(following-sibling::node()//Br)"&gt; &lt;xsl:call-template name="buildTree"&gt; &lt;xsl:with-param name="pLeafs" select= "following-sibling::node()"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;xsl:call-template name="Split"&gt; &lt;xsl:with-param name="pSplitters" select= "$pSplitters[position() &gt; 1]"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:for-each&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;xsl:template name="buildTree"&gt; &lt;xsl:param name="pAncestors" select="ancestor::*"/&gt; &lt;xsl:param name="pLeafs"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="not($pAncestors)"&gt; &lt;xsl:copy-of select="$pLeafs"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:variable name="vtopAncestor" select="$pAncestors[1]"/&gt; &lt;xsl:element name="{name($vtopAncestor)}" namespace="{namespace-uri($vtopAncestor)}"&gt; &lt;xsl:copy-of select= "$vtopAncestor/namespace::* | $vtopAncestor/@*"/&gt; &lt;xsl:call-template name="buildTree"&gt; &lt;xsl:with-param name="pAncestors" select="$pAncestors[position()&gt;1]"/&gt; &lt;xsl:with-param name="pLeafs" select="$pLeafs"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:element&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&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;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bar"&gt; &lt;Content&gt;foo&lt;/Content&gt; &lt;Br /&gt; &lt;Content&gt;bar&lt;/Content&gt; &lt;/CharacterStyleRange&gt; &lt;CharacterStyleRange style="bop"&gt; &lt;Content&gt;baz&lt;/Content&gt; &lt;Br /&gt; &lt;Hyperlink&gt; &lt;Content&gt;boo&lt;/Content&gt; &lt;Br /&gt; &lt;Content&gt;meep&lt;/Content&gt; &lt;/Hyperlink&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bar"&gt; &lt;Content&gt;foo&lt;/Content&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&gt; &lt;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bar"&gt; &lt;Content&gt;bar&lt;/Content&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&gt; &lt;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bop"&gt; &lt;Content&gt;baz&lt;/Content&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&gt; &lt;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bop"&gt; &lt;Hyperlink&gt; &lt;Content&gt;boo&lt;/Content&gt; &lt;/Hyperlink&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&gt; &lt;ParagraphStyleRange style="foo"&gt; &lt;CharacterStyleRange style="bop"&gt; &lt;Hyperlink&gt; &lt;Content&gt;meep&lt;/Content&gt; &lt;/Hyperlink&gt; &lt;/CharacterStyleRange&gt; &lt;/ParagraphStyleRange&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