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

[XSL-FO] RE: $ and Commas - How do we parse these out of data

Expand Messages
  • Quintens Raf
    To apply formatting to numbers there is the format-number function Format: format-number(value, format, [name]) = number Value is the input Format is the
    Message 1 of 4 , Sep 7, 2001
    • 0 Attachment
      To apply formatting to numbers there is the format-number function

      Format:
      format-number(value, format, [name]) => number

      Value is the input
      Format is the format pattern: almost equal to formatting in Java
      fe . 22000.3 using pattern #,##0.00 is translated into 22,000.30
      Name (Optional) of the decimal format, If in your XSL is
      <xsl:decimal-format> which declares the source format for the numbers in
      your document, you should use the same name.

      I Hope this brief explanation helps.

      Raf

      -----Oorspronkelijk bericht-----
      Van: sg_goli@... [mailto:sg_goli@...]
      Verzonden: donderdag 6 september 2001 17:06
      Aan: XSL-FO@yahoogroups.com
      Onderwerp: [XSL-FO] $ and Commas - How do we parse these out of data


      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




      To unsubscribe from this group, send an email to:
      XSL-FO-unsubscribe@egroups.com



      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • 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 2 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.