[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: format-number() for a phone number?

Subject: Re: format-number() for a phone number?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 25 May 1999 23:31:42 +0100 (BST)
xsl format phone number
You don't need to go to java extensions to do this, you can do it within
XSLT. the following inserts - into strings of digits, you should be able
to modify it easily enough to insert () as well.

David

<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
  result-ns="">

<xsl:template  match="ssn">
  <xsl:call-template name="ssn-dash">
   <xsl:param name="count" expr="1"/>
   <xsl:param name="left" expr="."/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="ssn-dash" >
  <xsl:param-variable name="count"/>
  <xsl:param-variable name="left"/>
  <xsl:if test="($count=4) or ($count=6)">-</xsl:if>
  <xsl:choose>
    <xsl:when test="$count=6">
      <xsl:value-of select="$left"/>
    </xsl:when>
    <xsl:when test="starts-with($left,'0')">
      <xsl:text>0</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'0')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'1')">
      <xsl:text>1</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'1')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'2')">
      <xsl:text>2</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'2')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'3')">
      <xsl:text>3</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'3')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'4')">
      <xsl:text>4</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'4')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'5')">
      <xsl:text>5</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'5')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'6')">
      <xsl:text>6</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'6')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'7')">
      <xsl:text>7</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'7')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'8')">
      <xsl:text>8</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'8')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="starts-with($left,'9')">
      <xsl:text>9</xsl:text>
      <xsl:call-template name="ssn-dash">
        <xsl:param name="count" expr="$count+1"/>
        <xsl:param name="left" expr="substring-after($left,'9')"/>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.