How to get current date in xslt executed by XslCompiledTransform in .net core?

331 views Asked by At

XslCompiledTransform is a xsl 1.0 processor, which doesn't support the current-dateTime() function. I've tried using my own script like this:

<?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:my-scripts"                 
                exclude-result-prefixes="msxsl user">
    <xsl:output method="xml" indent="yes"/>

    <msxsl:script language="CSharp" implements-prefix="user">
        public string current-dateTime()
        {       
          return DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"); 
        } 
    </msxsl:script>  


    <xsl:template match="...">
        ...
        <xsl:value-of select="user:current-dateTime()"/></xsl:element> 
        ...
    </xsl:template>
</xsl:stylesheet>

And this works in .net framework, but not in .net core because it doesn't support scripts. How can I do this in .net core?

0

There are 0 answers