Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I. Plain XSLT 1.0 solution:</p> <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:template match="text()" name="split"&gt; &lt;xsl:param name="pText" select="."/&gt; &lt;xsl:if test="string-length($pText)"&gt; &lt;xsl:if test="not($pText=.)"&gt; &lt;br /&gt; &lt;/xsl:if&gt; &lt;xsl:value-of select= "substring-before(concat($pText,';'),';')"/&gt; &lt;xsl:call-template name="split"&gt; &lt;xsl:with-param name="pText" select= "substring-after($pText, ';')"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on this XML document</strong>:</p> <pre><code>&lt;t&gt;123 Elm Street;PO Box 222;c/o James Jones&lt;/t&gt; </code></pre> <p><strong>produces the wanted, corrected result</strong>:</p> <pre><code>123 Elm Street&lt;br /&gt;PO Box 222&lt;br /&gt;c/o James Jones </code></pre> <p><strong>II. FXSL 1 (for XSLT 1.0):</strong></p> <p>Here we just use the <strong><a href="http://fxsl.sf.net" rel="noreferrer">FXSL</a></strong> template <code>str-map</code> (and do not have to write recursive template for the 999th time):</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://fxsl.sf.net/" xmlns:testmap="testmap" exclude-result-prefixes="xsl f testmap" &gt; &lt;xsl:import href="str-dvc-map.xsl"/&gt; &lt;testmap:testmap/&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="vTestMap" select="document('')/*/testmap:*[1]"/&gt; &lt;xsl:call-template name="str-map"&gt; &lt;xsl:with-param name="pFun" select="$vTestMap"/&gt; &lt;xsl:with-param name="pStr" select= "'123 Elm Street;PO Box 222;c/o James Jones'"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="replace" mode="f:FXSL" match="*[namespace-uri() = 'testmap']"&gt; &lt;xsl:param name="arg1"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="not($arg1=';')"&gt; &lt;xsl:value-of select="$arg1"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt;&lt;br /&gt;&lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on any XML document (not used), the same, wanted correct result is produced</strong>:</p> <pre><code>123 Elm Street&lt;br/&gt;PO Box 222&lt;br/&gt;c/o James Jones </code></pre> <p><strong>III. Using XSLT 2.0</strong></p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:template match="text()"&gt; &lt;xsl:for-each select="tokenize(.,';')"&gt; &lt;xsl:sequence select="."/&gt; &lt;xsl:if test="not(position() eq last())"&gt;&lt;br /&gt;&lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on this XML document</strong>:</p> <pre><code>&lt;t&gt;123 Elm Street;PO Box 222;c/o James Jones&lt;/t&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>123 Elm Street&lt;br /&gt;PO Box 222&lt;br /&gt;c/o James Jones </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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