I have a scenario where I cannot control the input data, for example, my input can be
<phoneNumber>6504323957</phoneNumber>
or
<phoneNumber>650-432-3957</phoneNumber>
or
<phoneNumber>(650)432-3957</phoneNumber>
or
<phoneNumber>650.432.3957</phoneNumber>
however my output should always be like this
<areaCode>650</areaCode>
<phoneNumber>432-3957</phoneNumber>
I’m trying to achieve this using the following xsl, which works only for one condition not for other.
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:element name="areaCode">
<xsl:value-of select="substring(phoneNumber,1,3)"/>
</xsl:element>
<xsl:element name="phoneNumber">
<xsl:value-of select="substring(phoneNumber,5,12)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Try
To handle input without area code you could use some simple math, and select from the right instead of from the left (assuming a full phone is 10 digits)..