Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edited</strong>: Per clarification from the original poster, the first string delimited by the underscores should not have its starting letter capitalized.</p> <p><strong>This solution does not use recursion and should be quite more efficient</strong>.</p> <p><strong>Here is the new solution</strong>:</p> <pre><code>string-join( (for $i in 1 to count(tokenize(.,'_')), $s in tokenize(.,'_')[$i], $fl in substring($s,1,1), $tail in substring($s,2) return if($i eq 1) then $s else concat(upper-case($fl), $tail) ), '' ) </code></pre> <p>The result is now exactly as required:</p> <pre><code>underLinedString </code></pre> <p><strong>Below is the old solution</strong>.</p> <p><strong>The replace() function supposes that you have a fixed replacement</strong> -- therefore it is not the best tool for solving this problem.</p> <p><strong>Here is a one-liner XPath 2.0 solution</strong> (and it certainly can be used as part of an XSLT 2.0 transformation :)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;):</p> <pre><code>string-join( (for $s in tokenize(.,'_'), $fl in substring($s,1,1), $tail in substring($s,2) return concat(upper-case($fl), $tail) ), '' ) </code></pre> <p><strong>When we use the above expression in an XSLT 2.0 transformation like this</strong>:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xsl:template match="/"&gt; &lt;xsl:sequence select= "string-join( (for $s in tokenize(.,'_'), $fl in substring($s,1,1), $tail in substring($s,2) return concat(upper-case($fl), $tail) ), '' ) "/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>and apply it on this XML document:</p> <pre><code>&lt;t&gt;under_lined_String&lt;/t&gt; </code></pre> <p><strong>the wanted result is produced</strong>:</p> <pre><code>UnderLinedString </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