xsl-list
[Top] [All Lists]

Re: [xsl] Structuring templates

2017-09-01 11:46:29
On 01.09.2017 18:16, Joseph L. Casale jcasale(_at_)activenetwerx(_dot_)com 
wrote:
I am trying to split up a few large xsl templates where one contains a
large block of msxsl:script based C# functions. Almost all of the templates
use some quantity of the functions made available through this facility
as well as some quantity of shared variables for data like apostrophes,
quotes and some common names.

Ultimately I want most of the templates in their own file, I intend to import
these in a single file for my primary use case but use them individually where
needed. Using import and include where it makes sense, this works fine for the
variable template but not for the C# functions. I seem to only be able to import
the template which defines the C# functions in just one file. Obviously that 
only
works if I place the C# import in the final template which imports everything 
but
that makes the individual templates useless.

The c# file resembles:

<?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:csharp="urn:csharp/functions"
                 exclude-result-prefixes="msxsl csharp">

   <msxsl:script language="C#" implements-prefix="csharp">
     <![CDATA[ ... ]]>
   </msxsl:script>

</xsl:stylesheet>

The other templates have the same namespace structure. How can I make the
C# functions available in each template so they are usable on their own?

Are you aware that XslCompiledTransform supports extension objects as well as inline code? If you encapsulate your C# code in a class and pass that as an extension object with e.g. https://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltargumentlist.addextensionobject(v=vs.110).aspx when you run XSLT then you don't depend on inline script compilation and execution and I think it should also solve the problem you have with sharing the C# code.

Obviously that way you need to write and compile the C# separately instead of having XslCompiledTransform doing it for the inline code, I am not sure whether it is an option.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>