[
https://issues.apache.org/jira/browse/XALANJ-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13542201#comment-13542201
]
alebor commented on XALANJ-2565:
--------------------------------
I came up with the following workaround for this issue, that work for me:
Java:
====
.....
// Transform message
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xslt);
transformer.setParameter("fmt", getFormatPattern()); // set fmt parameter used
by xslt file
transformer.setParameter("locale", locale.getCountry().toLowerCase()); // set
locale parameter used by xslt file
transformer.transform(in, result);
.....
protected String getFormatPattern() {
String decimalSeparator =
Character.toString(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator());
String groupingSeparator =
Character.toString(decimalFormat.getDecimalFormatSymbols().getGroupingSeparator());
// workaround for XALANJ-2565 bug
String formatPattern = "#,###.###";
if (",".equals(decimalSeparator) || ".".equals(groupingSeparator)) {
formatPattern = "#.###,###";
}
return formatPattern;
}
XSLT file:
=======
<xsl:param name="fmt"/>
<xsl:param name="locale"/>
<!-- Supported locales in the XSLT file, allowed to be set from Java-->
<xsl:decimal-format name="de" decimal-separator=","
grouping-separator="." />
<xsl:decimal-format name="fr" decimal-separator=","
grouping-separator=" " />
<xsl:decimal-format name="gb" decimal-separator="."
grouping-separator="," />
<xsl:decimal-format name="us" decimal-separator="."
grouping-separator="," />
.....
<xsl:value-of select="format-number(./@value, $fmt, $locale)"/>
.....
> java.lang.RuntimeException: ElemTemplateElement error: Malformed format
> string
> -------------------------------------------------------------------------------
>
> Key: XALANJ-2565
> URL: https://issues.apache.org/jira/browse/XALANJ-2565
> Project: XalanJ2
> Issue Type: Bug
> Security Level: No security risk; visible to anyone(Ordinary problems in
> Xalan projects. Anybody can view the issue.)
> Components: Xalan
> Affects Versions: 2.7.1
> Environment: Java 1.6.37 + Glassfish 3.0.1 + Xalan 2.7.1
> Reporter: alebor
> Assignee: Steven J. Hathaway
> Fix For: 2.7.1
>
> Attachments: XALANJ-2565.zip
>
>
> Setting decimal format decimal/grouping separators causes runtime exception.
> It looks like when "'#,###.###" pattern is used, you are not allowed to use
> "." for grouping separator and "," for decimal separator while from
> format-number documentation this should be possible since "," and "." specify
> the POSITION of the separators.
> Documentation:
> ===========
> string format-number(number,format,[decimalformat])
> number Required. Specifies the number to be formatted
> format Required. Specifies the format pattern. Here are some of the
> characters used in the formatting pattern:
> 0 (Digit)
> # (Digit, zero shows as absent)
> . (The position of the decimal point Example: ###.##)
> , (The group separator for thousands. Example: ###,###.##)
> % (Displays the number as a percentage. Example: ##%)
> ; (Pattern separator. The first pattern will be used for positive numbers
> and the second for negative numbers)
> decimalformat Optional.
> EXCEPTION:
> =========
> SEVERE: SystemId Unknown; Line #57; Column #73; java.lang.RuntimeException:
> ElemTemplateElement error: Malformed format string: #,###.###
> Example:
> ======
> <xsl:output method="text" encoding="iso-8859-1"/>
> <!-- This format has no name, so it's assumed to be the default. -->
> <xsl:decimal-format decimal-separator="," grouping-separator="."/>
> <xsl:if test="./@actualValue">
> <xsl:value-of select="format-number(./@actualValue, '#,###.###')"/>
> </xsl:if>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]