RE: [Fwd: [Visual-XSLT-discuss] debugger exception while using urn:schemas-microsoft-com:xslt:format-date]
by Kirk Allen Evans other posts by this author
Sep 4 2002 10:24PM messages near this date
view in the new Beta List Site
Re: [Fwd: [Visual-XSLT-discuss] debugger exception while using urn:schemas-microsoft-com:xslt:format-date]
|
Re: [Fwd: [Visual-XSLT-discuss] debugger exception while using urn:schemas-microsoft-com:xslt:format-date]
Here is a repro of the post to xsl-list@mulberrytech.com:
The extension functions defined in urn:schemas-microsoft-com:xslt are
not supported in .NET, they are only supported in MSXML 4.0, as noted in
my post at Microsoft.public.dotnet.xml [1]. This was confirmed as well
by Chris Lovett and Dare Obasanjo, both of Microsoft.
You can still use C# extensions, and you don't have to resort to using
extension objects with XsltArgumentList: Since .NET's XSLT parser
supports C#, you can use some of the .NET framework classes directly in
conjunction with the msxsl:script element. Agreed that the
msxsl:format-date function is easier to manage than the System.DateTime
approach, using inline extensions seems to help simplify the solution
somewhat (although I would prefer the ability to debug compiled objects
rather than rely on an external debugger, even though VisualXSLT rocks)
).
If they don't want to inline the extension, you can use an XSLT include
or import to pull the vendor-specific stuff in (or hide it and make it
easier to work with). I would have named the function "format-date" for
consistency, but C# balked at that name. I posted the stylesheet to be
imported at my web site (URL in the stylesheet below) to show a working
demonstration:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="urn:schemas-xmlandasp-net:xslt">
<xsl:import href="http://www.xmlandasp.net/msxslext.xslt"/>
<xsl:template match="/">
<h1> user:FormatDate</h1>
<xsl:value-of
select="foo:formatdate('1996-08-01','MMMM')"/>
</xsl:template>
</xsl:stylesheet>
Here is what the combined stylesheet (including import) really looks
like, should they choose to use a local copy instead of pulling from a
remote server.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:schemas-xmlandasp-net:xslt">
<msxsl:script language="C#" implements-prefix="user">
string formatdate(string wholeDate,string format)
{
string yearPart = wholeDate.Substring(0,4);
string monthPart = wholeDate.Substring(5,2);
string dayPart = wholeDate.Substring(8,2);
DateTime mydate = new
DateTime(int.Parse(yearPart),int.Parse(monthPart),int.Parse(dayPart));
return(mydate.ToString(format));
}
</msxsl:script>
<xsl:template match="/">
<h1> user:formatDate</h1>
<xsl:value-of
select="user:formatdate('1996-08-01','MMMM')" />
</xsl:template>
</xsl:stylesheet>
[1]
http://groups.google.com/groups?q=evans+date+xslt&hl=en&lr=&ie=UTF-8&oe=
UTF-8&selm=eJLf8BJ7BHA.2464%40tkmsftngp05&rnum=2
Kirk Allen Evans
http://www.xmlandasp.net
Author, "XML And ASP.NET", New Riders Publishing
http://www.amazon.com/exec/obidos/ASIN/073571200X
_______________________________________________
Visual-XSLT-discuss mailing list
Visual-XSLT-discuss@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Eric Promislow
Kirk Allen Evans
Eric Promislow
|