Aussie Mike Posted September 15, 2009 Report Share Posted September 15, 2009 Hi i have a counting number i continually recieve in messages the number is going to continue counting and adding digitse.g. <number>54321</number> will eventually be <number>654321</number> AND <number>987654321</number> and so on.What i want is only digits 1,2,and 3as the total length will change i cant use substring-after(//number,3,3) which would work for the first as when i hit 9 digits it would give a different result Link to comment Share on other sites More sharing options...
Martin Honnen Posted September 15, 2009 Report Share Posted September 15, 2009 Is it ensured that there are at least three digits? Then you can use e.g.substring(number, string-length(number) - 2)to extract the last three digits. Link to comment Share on other sites More sharing options...
Aussie Mike Posted September 16, 2009 Author Report Share Posted September 16, 2009 Is it ensured that there are at least three digits? Then you can use e.g.substring(number, string-length(number) - 2)to extract the last three digits.For one of the uses i need it for that is the case so i will use this thanks.But for another it could be from 1-8 digits then it recycles and can only take 5 of them. Must be the last 5Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted September 16, 2009 Report Share Posted September 16, 2009 You could use xsl:choose to react based on the length. E.g. <xsl:variable name="strlen" select="string-length(number)" /><xsl:choose> <xsl:when test="$strlen < 8 and $strlen > 1"> <xsl:value-of select="substring(number, $strlen - 5)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring(number, $strlen - 2)" /> </xsl:otherwise></xsl:choose> Link to comment Share on other sites More sharing options...
Aussie Mike Posted September 16, 2009 Author Report Share Posted September 16, 2009 You could use xsl:choose to react based on the length. E.g.<xsl:variable name="strlen" select="string-length(number)" /><xsl:choose> <xsl:when test="$strlen < 8 and $strlen > 1"> <xsl:value-of select="substring(number, $strlen - 5)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring(number, $strlen - 2)" /> </xsl:otherwise></xsl:choose> Brilliant...!! Needed to tweak the numbers. When there was 1 digit or 8 digits it gave empty value, and it was outputting 6 not 5 digits. <xsl:when test="$strlen < 9 and $strlen > 0"> <xsl:value-of select="substring(//deal_no, $strlen - 4)" />Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now