Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>XSLT 2.0 has <code>xsl:analyze-string</code> which is designed for precisely this task, so if at all possible I suggest you upgrade to a 2.0 processor such as <a href="http://www.saxonica.com/welcome/welcome.xml" rel="nofollow">Saxon</a>:</p> <pre><code>&lt;xsl:template match="node"&gt; &lt;failure&gt; &lt;xsl:analyze-string select="failure" regex="^\s*CRS\s*(\S+)\s*(not\s*.*)$" flags="m"&gt; &lt;xsl:matching-substring&gt; &lt;CRS&gt; &lt;id&gt;&lt;xsl:value-of select="regex-group(1)" /&gt;&lt;/id&gt; &lt;result&gt;&lt;xsl:value-of select="normalize-space(regex-group(2))" /&gt;&lt;/result&gt; &lt;/CRS&gt; &lt;/xsl:matching-substring&gt; &lt;/xsl:analyze-string&gt; &lt;/failure&gt; &lt;/xsl:template&gt; </code></pre> <p>String manipulation facilities in XSLT 1.0 are extremely limited in comparison, and since XSLT is a functional language without updateable variables you'd have to write some sort of hideously complex set of recursive <code>call-template</code> logic to split up the text into separate lines and then extract the relevant bits out of each line in turn using <code>substring-before</code> and <code>substring-after</code>.</p> <pre><code>&lt;xsl:template name="each-line"&gt; &lt;xsl:param name="val" /&gt; &lt;!-- pull out everything before the first newline and normalize (trim leading and trailing whitespace and squash internal whitespace to a single space character --&gt; &lt;xsl:variable name="firstLine" select="normalize-space(substring-before($val, '&amp;#10;'))" /&gt; &lt;!-- pull out everything after the first newline --&gt; &lt;xsl:variable name="rest" select="substring-after($val, '&amp;#10;')" /&gt; &lt;xsl:if test="$firstLine"&gt; &lt;xsl:call-template name="process-line"&gt; &lt;xsl:with-param name="line" select="$firstLine" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;!-- if there are still some non-empty lines left then process them recursively --&gt; &lt;xsl:if test="normalize-space($rest)"&gt; &lt;xsl:call-template name="each-line"&gt; &lt;xsl:with-param name="val" select="$rest" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;xsl:template name="process-line"&gt; &lt;xsl:param name="line" /&gt; &lt;xsl:if test="starts-with($line, 'CRS ') and contains($line, ' not ')"&gt; &lt;!-- here $line will be something like "CRS urn:ogc:def:crs:EPSG::25830 not defined." --&gt; &lt;CRS&gt; &lt;!-- ID is everything between the first and second spaces --&gt; &lt;id&gt;&lt;xsl:value-of select="substring-before(substring-after($line, ' '), ' ')" /&gt;&lt;/id&gt; &lt;!-- result is everything after the second space --&gt; &lt;result&gt;&lt;xsl:value-of select="substring-after(substring-after($line, ' '), ' ')" /&gt;&lt;/result&gt; &lt;/CRS&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; </code></pre> <p>You would call this logic using a construct like</p> <pre><code>&lt;xsl:template match="node"&gt; &lt;failure&gt; &lt;xsl:call-template name="each-line"&gt; &lt;xsl:with-param name="val" select="failure" /&gt; &lt;/xsl:call-template&gt; &lt;/failure&gt; &lt;/xsl:template&gt; </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.
 

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