user5458829
user5458829

Reputation: 163

XSLT concat function

Hi all I was having a scenario to add zero in the right of value dynamically based on string length for 17 character and if it less it will add the required no of zero at the end to make it 17 character long. $normalizedTime2 value is dynamic one any value it can come which is less then 17 characters long.

I am trying this below approach but it is now working as expected.

Ex: if i am getting value like 2016050611525 the out put should be 20160506115250000 . the incoming value is dynamic.

    <xsl:variable name="normalizedTime2" select="2016050611525"/>
    <xsl:variable name="normalizedTime">
          <xsl:choose>
            <xsl:when test="string-length(normalize-space($normalizedTime2)) &lt; 17">
              <xsl:value-of select="substring(concat(., '00000000000000000'),1,17)"/>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$normalizedTime2"/></xsl:otherwise>
          </xsl:choose>   
    </xsl:variable>

Let me know the issue .

Upvotes: 1

Views: 573

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117073

I believe that your example should have:

<xsl:value-of select="substring(concat($normalizedTime2, '00000000000000000'),1,17)"/>

instead of:

<xsl:value-of select="substring(concat(.,'00000000000000000'),1,17)"/>

And I am not sure why you need the xsl:choose instruction - unless you expect input strings longer than 17 characters and don't want to cut them off. Otherwise you could just do:

<xsl:value-of select="substring(concat($inputString, '00000000000000000'), 1, 17)"/>

for any input.

Upvotes: 1

Related Questions