xslt

Formatting an XSLT to add a * into a number


Fairly new to XSLT format and trying to have it output 2 numbers based on 1 input. I've tried a few things and it hasn't been working. Lets say that it gets 8989 from telephoneNumber as it's linked to LDAP. I want one output as 8989, which I get. I need another that is 8*989, so the XSLT file needs to insert a * as the second digit. Any help would be greatly appreciated!

For the single output, this works:

    <Extension>
        <xsl:value-of select="telephonenumber"/>
    </Extension>

So for multi I guess I need the below with the adaptation of the number to include the * where the #*### is?

    <xsl:for-each select="telephoneNumber">
    <Extension>
        <xsl:value-of select="."/>
        <xsl:value-of select="#*###"/>
        </Extension>
    </xsl:for-each>

Thanks, Scutch


Solution

  • After much trial and error this worked in my scenario, adding both the telephone number e.g. 8989, and the transformed extension 8*989 as a separate extension.

    <Extensions>
        <Extension>
            <xsl:value-of select="telephonenumber"/>
        </Extension>
        <Extension>
            <xsl:value-of select="concat((substring(telephonenumber,1,1)),'*',(substring(telephonenumber,2,3)))"/>
        </Extension>
    </Extensions>