I am trying to handle a space issue with the Phone number and faxNumber elements in my XML.
The elements are:
<PhoneNumber>0870 6071352</PhoneNumber>
<FaxNumber>01722 422301</FaxNumber>
but they can also be:
0870 6071352
so I need to remove the leading and trailing spaces, keep the space between any numbers, and output the result formatted to a fixed length of 71 characters using leading spaces.
so I am trying to write a named template that will remove the spaces then pad the output with leading spaces to a fixed length of 71 characters.
here is my defined template but it doesn't compile - I get an error Expression expected <- and I can't find out what is missing or wrong
<!-- format the phone number with no spaces and output to 71 characters with leading spaces -->
<xsl:template name="FormattedPhoneFaxNumber">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,' ')">
<xsl:value-of select="substring-before($text,' ')"/>
<xsl:value-of select=""/>
<xsl:call-template name="FormattedPhoneFaxNumber">
<xsl:with-param name="text" select="substring-after($text,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(concat(' ', $text), 1, 71)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
can anyone show me where I am going wrong?
The reason I need to do this is because I have to handle the element being empty, having leading or trailing spaces as well as the value, or just the value, and we need to output two fiwlds with leading spaces to a max length of 71 characters.