Loading ...
Sorry, an error occurred while loading the content.

Re: $ and Commas - How do we parse these out of data

Expand Messages
  • neuggs@concentric.net
    Sangeetha, As a matter of design, having the dollar signs within the XML is less than ideal. This is because those numbers (i.e., TOTAL and the second
    Message 1 of 4 , Sep 7, 2001
    • 0 Attachment
      Sangeetha,

      As a matter of design, having the dollar signs within the XML is less
      than ideal. This is because those numbers (i.e., "TOTAL" and the
      second "LIMIT") are no longer numbers, they're strings. As such,
      format-number won't work. Furthermore, dollar signs are for display
      only and not really part of the "data." That's what something like
      format-number is for. This same kind of problem is evident when
      calculations (you can't do math with a string) come into play.

      That said, I would first try and modify the XML to get rid of the
      dollar signs. If you can, then you're in good shape. Change the XML
      and use format-number.

      If not, and I suspect this is probably the case, then you'll first
      need to use string manipulation to get rid of the dollar sign (that
      should be pretty simple). In other words, get rid of the dollar sign
      (you can keep the commas). Then, use format-number *after* you've
      converted the string (i.e., your numbers with dollar signs) to a
      number.

      Here's an example that does it both ways.

      XML:
      <?xml version='1.0'?>
      <Number>
      <First>10,224.25</First>
      <Second>$25,202.22</Second>
      </Number>

      XSL Stylesheet:
      <?xml version='1.0'?>

      <xsl:stylesheet
      xmlns:xsl='http://www.w3.org/199/XSL/Transform'
      version='1.0'>

      <xsl:template match="Number">
      <!-- Easy way -->
      <xsl:value-of select="format-number(./First, '$##,###.##')"/>

      <!-- Less easy way -->
      <xsl:value-of
      select="format-number(substring-after(./Second,'$'),
      '$##,###.##')"/>
      </xsl:template>
      </xsl:stylesheet>

      The "Easy way" simply takes the "First" element and formats it.
      The "Less easy way" first converts the "Second" element by stripping
      off the dollar sign, then apply the formatting. If you're not 100%
      sure if there will be a dollar sign, then you'll need to check using
      something like "starts-with" in a conditional.

      Hope this helps.

      Regards,
      Frank.


      --- In XSL-FO@y..., sg_goli@y... wrote:
      > Hi,
      >
      > I have an XML file which has the following data.
      >
      > <LIMIT>10000</LIMIT>
      > <TOTAL>$22,000.34</TOTAL>
      >
      >
      > <LIMIT>$30,000</LIMIT>
      > <TOTAL>$77,000.99</TOTAL>
      >
      >
      > How do i check these elements and parse out the punctuation in
      the
      > XML and apply my own formatting and display using XSL.
      >
      > Thanks
      > Sangeetha
    Your message has been successfully submitted and would be delivered to recipients shortly.