我正在尝试处理我的 XML 中的电话号码和传真号码元素的空间问题。
元素是:
<PhoneNumber>0870 6071352</PhoneNumber>
<FaxNumber>01722 422301</FaxNumber>
但它们也可以是:
0870 6071352
所以我需要删除前导和尾随空格,保留任何数字之间的空格,并使用前导空格将结果格式化为固定长度的 71 个字符。
所以我正在尝试编写一个命名模板,该模板将删除空格,然后用前导空格填充输出到固定长度的 71 个字符。
这是我定义的模板,但它没有编译 - 我收到一个错误Expression expected <-我找不到丢失或错误的地方
<!-- 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>
谁能告诉我哪里出错了?
我需要这样做的原因是因为我必须处理元素为空、具有前导或尾随空格以及值或仅值,并且我们需要输出两个带前导空格的字段,最大长度为 71人物。