 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 26th, 2005, 02:20 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
format-number in a template
Hi,
I have a stylesheet that has many entries as follows:
<xsl:value-of select="format-number(number(curAmount1), '###,##0.00')" />
<xsl:value-of select="format-number(number(curAmount2), '###,##0.00')" />
<xsl:value-of select="format-number(number(curAmount3), '###,##0.00')" />
I would like to achive the following without having to do a change all in the xsl stylesheet
<xsl:value-of select="format-number(number(curAmountX), '### ##0,00;(### ##0,00)',' fmCurrency')"/>
where fmCurrency
<xsl:decimal-format name=" fmCurrency" decimal-separator="," grouping-separator=" "/>
So I would like to replace this string
###,##0.00
with
### ##0,00;(### ##0,00)','fmCurrency
by including an external stylesheet (<xsl:include â¦) using templates
I do not want to use templates with xsl:param as following
<xsl:template name="fmToCurrency">
<xsl:param name="amt"/>
<xsl:value-of select="format-number($amt , '# ##0,00;(# ##0,00)', âfmCurrencyâ)"/>
</xsl:template>
because I would have to change in the xsl all reference to currency with <xsl:call-template name=" fmToCurrency ">
<xsl:with-param name="amt" (so I might as well to a change all in the xsl)
any idea?
Thanks.
|
|

April 26th, 2005, 02:58 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Just define the format in a global variable (or even a global param)
<xsl:param name="format" select="'# ##0,00;(# ##0,00)'"/>
and pick it up using
format-number($amt, $format, 'fmCurrency')
You can override the value of the variable or param in an importing stylesheet.
(or have I misunderstood something?)
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 26th, 2005, 04:11 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using a software that generates my xsl. The software generates an xsl with <xsl:value-of select="format-number(number(curAmount1), '###,##0.00')" />
If I do what you suggested, wouldnât I have to do a change all in my xsl
With '###,##0.00' replaced by $format, 'fmCurrency ? If this is the case, then it would be the same as doing a change all from ###,##0.00 to ### ##0,00;(### ##0,00)','fmCurrency
What Iâd like to do is have a template (include_currency_change ) xsl
containing this line
<xsl:decimal-format name=" fmCurrency" decimal-separator="," grouping-separator=" "/>
and something that would match ###,##0.00 from the generated xsl and convert it to the $format, 'fmCurrency that you have suggested.
So that everytime I generate the xsl with the software, all I have to do is include in that file my template to change all occurrence of currency instead of doing a change all.
<xsl:include href="include_currency_change.xsl"/>
Does this make any sense?
|
|

April 26th, 2005, 04:32 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
No, your idea won't work. A template within a stylesheet cannot modify the code of the stylesheet.
When you use a tool to generate XSLT (or any other language) you ave to accept that either (a) you are restricted to the subset of XSLT that the tool can generate, or (b) you are going to have to modify the generated XSLT code, giving consequent maintenance difficulties. I personally have a strong dislike of program generators for that reason.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 27th, 2005, 11:31 AM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I figure if you can change an xml to modify it's processing instructions and add element and attributes that you could do the same with a template in external xsl.
Right tools help build things faster. Not using the tool would be like cutting wood with hand saw instead of an electric one. I don't use notepad to write code because of time issue.
Thank you Mh global variable will work just fine!
My bad. Doing a change all to ### ##0,00;(### ##0,00)','fmCurrency is not the same as a change all to $format,'fmCurrency. In the sense that should the format change only one place in one file need to be changed.
Thank you.
|
|
 |