Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This is a <em>two-pass</em> transformation that produces the wanted result</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="@*|node()" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="vrtfPass1"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name="vPass1" select="ext:node-set($vrtfPass1)/*"/&gt; &lt;xsl:apply-templates select="$vPass1" mode="pass2"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="content"&gt; &lt;wrapper&gt; &lt;replace /&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/wrapper&gt; &lt;/xsl:template&gt; &lt;xsl:template match="replace"&gt; &lt;xsl:text&gt;&amp;#xA;Hello world&amp;#xA;&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*|node()" mode="pass2"&gt; &lt;xsl:call-template name="identity"/&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;example&gt; &lt;content&gt;Lorem ipsum&lt;/content&gt; &lt;content&gt;&lt;replace /&gt;&lt;/content&gt; &lt;/example&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;example&gt; &lt;wrapper&gt; Hello world Lorem ipsum&lt;/wrapper&gt; &lt;wrapper&gt; Hello world Hello world &lt;/wrapper&gt; &lt;/example&gt; </code></pre> <p><strong>Do note</strong>:</p> <p>In XSLT 1.0 the result of applying templates is of the infamous type RTF (Result Tree Fragment) and by definition it cannot be further accessed and processed, except using <code>xsl:copy-of</code> and the standard string functions.</p> <p>This is why almost every XSLT 1.0 processor provides a vendor-specific extension function <code>xxx:node-set()</code> that takes an RTF and converts it to a "regular" tree whoce descendants can be accessed using any XPath expression. Here the <code>xxx</code> prefix must be bound to a vendor-specifix namespace-uri.</p> <p>The EXSLT <code>ext:node-set()</code> is implemented by most XSLT processors -- thus its use guarantees significant degree of portability among different XSLT processors.</p> <p><strong>For an additional multi-pass transformation example, see this</strong>:</p> <p><a href="https://stackoverflow.com/a/3200026/36305">https://stackoverflow.com/a/3200026/36305</a></p> <p><strong>and this</strong>:</p> <p><a href="http://www.dpawson.co.uk/xsl/sect1/N169.html#d860e392" rel="nofollow noreferrer">http://www.dpawson.co.uk/xsl/sect1/N169.html#d860e392</a></p>
    singulars
    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.
    2. 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