<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://www.xlayer.co.za/forum/extern.php?action=feed&amp;tid=78&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[SXI Forum / Padding Zeros to a Field with XSLT]]></title>
		<link>https://www.xlayer.co.za/forum/viewtopic.php?id=78</link>
		<description><![CDATA[The most recent posts in Padding Zeros to a Field with XSLT.]]></description>
		<lastBuildDate>Fri, 08 Mar 2019 19:04:55 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: Padding Zeros to a Field with XSLT]]></title>
			<link>https://www.xlayer.co.za/forum/viewtopic.php?pid=130#p130</link>
			<description><![CDATA[<p>Thx Sean, works like a charm.</p>]]></description>
			<author><![CDATA[dummy@example.com (StephanB)]]></author>
			<pubDate>Fri, 08 Mar 2019 19:04:55 +0000</pubDate>
			<guid>https://www.xlayer.co.za/forum/viewtopic.php?pid=130#p130</guid>
		</item>
		<item>
			<title><![CDATA[Re: Padding Zeros to a Field with XSLT]]></title>
			<link>https://www.xlayer.co.za/forum/viewtopic.php?pid=129#p129</link>
			<description><![CDATA[<p>Is there a reason this is not being done with a standard XLayer rule?</p><p>Given a field called &quot;<em>aNum</em>&quot; that contains &quot;12345&quot;&#160; The following XLayer rule will product &quot;0000012345&quot;</p><div class="codebox"><pre><code>&lt;sxi:Rules&gt;
    &lt;sxi:SubStringReplace&gt;
        &lt;sxi:StartAt&gt;-1&lt;/sxi:StartAt&gt;
        &lt;sxi:Pattern&gt;0000000000&lt;/sxi:Pattern&gt;
        &lt;sxi:ReplaceWith input=&quot;yes&quot;&gt;aNum&lt;/sxi:ReplaceWith&gt;
    &lt;/sxi:SubStringReplace&gt;
&lt;/sxi:Rules&gt;</code></pre></div><p>No need to stylesheet Kung-Fu.&#160; Unless obviously you absolutely have to do it in a stylesheet.</p>]]></description>
			<author><![CDATA[dummy@example.com (SeanR)]]></author>
			<pubDate>Fri, 08 Mar 2019 10:03:15 +0000</pubDate>
			<guid>https://www.xlayer.co.za/forum/viewtopic.php?pid=129#p129</guid>
		</item>
		<item>
			<title><![CDATA[Padding Zeros to a Field with XSLT]]></title>
			<link>https://www.xlayer.co.za/forum/viewtopic.php?pid=128#p128</link>
			<description><![CDATA[<p>Padding Zeros to a Field with XSLT</p><div class="codebox"><pre class="vscroll"><code>&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;2.0&quot;&gt;
    &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot;/&gt;
    &lt;xsl:strip-space elements=&quot;*&quot;/&gt;
    &lt;!-- identity transform --&gt;
    &lt;xsl:template match=&quot;@*|node()&quot;&gt;
        &lt;xsl:copy&gt;
            &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    
    &lt;xsl:template match=&quot;//*[local-name()=&#039;CustomerCode&#039;]&quot;&gt;
        &lt;!-- Define a variable to contain the length of the input value
            The dot you see in the expression is the current element we are working on. 
            In this case CustomerCode is  the Input Value. See the match above--&gt;
        &lt;xsl:variable name=&quot;inputLength&quot; select=&quot;string-length(.)&quot; /&gt;
        &lt;xsl:copy&gt;
            &lt;!-- Now we create a variable to hold our padding. 
                It is a substring of our 10 zeros less the length of our input --&gt;
            &lt;xsl:variable name=&quot;padding&quot; select=&quot;substring(&#039;0000000000&#039;,1,10 - $inputLength)&quot;/&gt;
            
            &lt;!-- Finally we simply concatinate our padding which is the correct length with the input value.
                Don&#039;t forget the dot you see there is the current element we matched on in this case CustomerCode Input Value --&gt;
            &lt;xsl:value-of select=&quot;concat($padding,.)&quot; /&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    
    &lt;xsl:template match=&quot;//*[local-name()=&#039;SiteCode&#039;]&quot;&gt;
        &lt;!-- Define a variable to contain the length of the input value
            The dot you see in the expression is the current element we are working on. 
            In this case SiteCode is  the Input Value. See the match above--&gt;
        &lt;xsl:variable name=&quot;inputLength&quot; select=&quot;string-length(.)&quot; /&gt;
        &lt;xsl:copy&gt;
            &lt;!-- Now we create a variable to hold our padding. 
                It is a substring of our 10 zeros less the length of our input --&gt;
            &lt;xsl:variable name=&quot;padding&quot; select=&quot;substring(&#039;0000000000&#039;,1,10 - $inputLength)&quot;/&gt;
            
            &lt;!-- Finally we simply concatinate our padding which is the correct length with the input value.
                Don&#039;t forget the dot you see there is the current element we matched on in this case SiteCode Input Value --&gt;
            &lt;xsl:value-of select=&quot;concat($padding,.)&quot; /&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</code></pre></div><br /><p>Here is the input XML you can test with</p><div class="codebox"><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;XServiceBroker xmlns=&quot;http://www.sxi.co.za/XMLSchema&quot;&gt;
    &lt;CustomerCode&gt;1222B3&lt;/CustomerCode&gt;
    &lt;SiteCode&gt;ZB22B3&lt;/SiteCode&gt;
&lt;/XServiceBroker&gt;</code></pre></div><p>Credit goes to Kevin.</p>]]></description>
			<author><![CDATA[dummy@example.com (StephanB)]]></author>
			<pubDate>Fri, 08 Mar 2019 05:08:40 +0000</pubDate>
			<guid>https://www.xlayer.co.za/forum/viewtopic.php?pid=128#p128</guid>
		</item>
	</channel>
</rss>
