Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed advice on using xsl choose with contains and substring
    text
    copied!<p>I think I have this working but I need advice. I'd like to know if this is a good setup for the requirement that I have. I've got a requirement to apply different transformation rules to an element based on what is contained in that element. I've tried to search for 'xsl' and 'choose', 'contains', 'substring'. I can't seem to find a solution applicable to this situation.</p> <p>Here are the various scenarios for this element:</p> <ol> <li><p>If it begins with U, I need everything before the '/'</p> <ul> <li><p>Original Value: UJXXXXX/001</p></li> <li><p>Transformed : UJXXXXX</p></li> </ul></li> <li><p>If it begins with ECG_001 I need everything after ECG_001</p> <ul> <li><p>Original Value: ECG_0012345678</p></li> <li><p>Transformed : 12345678</p></li> </ul></li> <li><p>If it does not meet the above criteria and contains a '/' take everyting after the '/'</p> <ul> <li><p>Original Value: F5M/12345678</p></li> <li><p>Transformed : 12345678</p></li> </ul></li> <li><p>If it does not meet 1,2, or 3 just give me the value</p> <ul> <li><p>Original Value : 12345678</p></li> <li><p>Transformed : 12345678</p></li> </ul></li> </ol> <p>Here is what I have so far:</p> <pre><code>&lt;xsl:variable name="CustomerPO"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="contains(substring(rma/header/CustomerPO,1,1), 'U')"&gt; &lt;xsl:value-of select="substring-before(rma/header/CustomerPO,'/')"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="contains(rma/header/CustomerPO, 'ECG_001')"&gt; &lt;xsl:value-of select="substring-after(rma/header/CustomerPO,'ECG_001')"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="contains(rma/header/CustomerPO, '/')"&gt; &lt;xsl:value-of select="substring-after(rma/header/CustomerPO, '/')"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="rma/header/CustomerPO"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; </code></pre> <p>Any feedback on potential loopholes or a more efficient way to accomplish this is appreciated.</p> <p>Thanks.</p>
 

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