Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Scientific (Engineering) format supported for multiplication operator?

From: barnum@--------.--
To: NULL
Date: 8/19/2008 8:07:00 AM
On Aug 18, 1:31=A0pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> bar...@bluezone.no wrote:
> > We may have a possibility to run this part in .Net (using
> > XslCompiledTransform). What's the best way to use an extension
> > function there?
>
> You can either use an extension function also implemented using
> msxsl:script but with a .NET language like C#
>
> <xsl:stylesheet
> =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> =A0 =A0xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt"
> =A0 =A0xmlns:my=3D"http://example.com/2008/mf"
> =A0 =A0exclude-result-prefixes=3D"my msxsl"
> =A0 =A0version=3D"1.0">
>
> =A0 =A0<xsl:output method=3D"html" indent=3D"yes"/>
>
> =A0 =A0<msxsl:script language=3D"C#" implements-prefix=3D"my">
> =A0 =A0 =A0public double stringToDouble(string s)
> =A0 =A0 =A0{
> =A0 =A0 =A0 =A0return double.Parse(s,
> System.Globalization.CultureInfo.InvariantCulture);
> =A0 =A0 =A0}
> =A0 =A0</msxsl:script>
>
> =A0 =A0<xsl:template match=3D"root">
> =A0 =A0 =A0<html lang=3D"en">
> =A0 =A0 =A0 =A0<head>
> =A0 =A0 =A0 =A0 =A0<title>Example</title>
> =A0 =A0 =A0 =A0</head>
> =A0 =A0 =A0 =A0<body>
> =A0 =A0 =A0 =A0 =A0<ul>
> =A0 =A0 =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"foo"/>
> =A0 =A0 =A0 =A0 =A0</ul>
> =A0 =A0 =A0 =A0</body>
> =A0 =A0 =A0</html>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"foo">
> =A0 =A0 =A0<li>
> =A0 =A0 =A0 =A0<xsl:value-of select=3D"@a1 * my:stringToDouble(string(@a2=
))"/>
> =A0 =A0 =A0</li>
> =A0 =A0</xsl:template>
>
> </xsl:stylesheet>
>
> Or you could implement an extension object that provides the
> functionality and pass it in using an XsltArgumentList:
>
> =A0 =A0 =A0public class MyConverter
> =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0public double StringToDouble(string s)
> =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0return double.Parse(s,
> System.Globalization.CultureInfo.InvariantCulture);
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0XslCompiledTransform xsltProc =3D new XslCompi=
ledTransform();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0xsltProc.Load(@"..\..\XSLTFile2.xslt");
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0XsltArgumentList argList =3D new XsltArgumentL=
ist();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0argList.AddExtensionObject("http://example.com=
/2008/mc",
> new MyConverter());
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0xsltProc.Transform(@"..\..\XMLFile1.xml", argL=
ist,
> Console.Out);
>
> where the stylesheet looks like this:
>
> <xsl:stylesheet
> =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> =A0 =A0xmlns:my=3D"http://example.com/2008/mc"
> =A0 =A0exclude-result-prefixes=3D"my"
> =A0 =A0version=3D"1.0">
>
> =A0 =A0<xsl:template match=3D"root">
> =A0 =A0 =A0<html lang=3D"en">
> =A0 =A0 =A0 =A0<head>
> =A0 =A0 =A0 =A0 =A0<title>Example</title>
> =A0 =A0 =A0 =A0</head>
> =A0 =A0 =A0 =A0<body>
> =A0 =A0 =A0 =A0 =A0<ul>
> =A0 =A0 =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"foo"/>
> =A0 =A0 =A0 =A0 =A0</ul>
> =A0 =A0 =A0 =A0</body>
> =A0 =A0 =A0</html>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"foo">
> =A0 =A0 =A0<li>
> =A0 =A0 =A0 =A0<xsl:value-of select=3D"@a1 * my:StringToDouble(string(@a2=
))"/>
> =A0 =A0 =A0</li>
> =A0 =A0</xsl:template>
>
> </xsl:stylesheet>
>
> The extension object is the more efficient solution as using
> msxsl:script with the .NET framework creates temporary assemblies you
> would need to clean up.
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/

Thanks, it works perfectly! Just a follow-up question: is the
performance penalty bad?


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent