How to - Centralized XSLT Library with Custom Functions?
Hi,
I am using some C# methods in some of my XSLT files more than once. Now I am wondering if there is a way I can include all my custom C# methods maybe XSLT templates in a single XSLT file or maybe some other way, so I can reference them from a central location.
I am sure this is possible and I am hoping someone can point me in the right direction or to some documentation. I did some searches but haven't found it yet.
Put your methods in a class using visual studio and put the .dll in bin folder. Register extension in xsltExtensions.xml and umbraco will include xmlns in your new .xslt's. In your old .xslt scripts you have to add xmlns yourself. See link for a more detailed walkthrough :)
Also, if you are using 4.6+ you can declare XSLT Extensions just by adding an attribute to your class, and you don't need to add it to the config file. See: http://www.nibble.be/?p=95
Since you mentioned XSLT templates I'll mention that its possible to include or import stylesheets, which is also great tool for not having duplicate templates lying around.
How to - Centralized XSLT Library with Custom Functions?
Hi,
I am using some C# methods in some of my XSLT files more than once. Now I am wondering if there is a way I can include all my custom C# methods maybe XSLT templates in a single XSLT file or maybe some other way, so I can reference them from a central location.
I am sure this is possible and I am hoping someone can point me in the right direction or to some documentation. I did some searches but haven't found it yet.
Thanks,
Jim
You can make a xslt-extension.
http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C
Put your methods in a class using visual studio and put the .dll in bin folder. Register extension in xsltExtensions.xml and umbraco will include xmlns in your new .xslt's. In your old .xslt scripts you have to add xmlns yourself. See link for a more detailed walkthrough :)
Excellent! This is exactly what I was looking for.
Hi,
Also, if you are using 4.6+ you can declare XSLT Extensions just by adding an attribute to your class, and you don't need to add it to the config file. See: http://www.nibble.be/?p=95
-Tom
Hi Jim,
Since you mentioned XSLT templates I'll mention that its possible to include or import stylesheets, which is also great tool for not having duplicate templates lying around.
/Chriztian
Thanks guys!
is working on a reply...