Solved

extending XSLT using C# classes

Posted on 2009-07-11
4
557 Views
Last Modified: 2013-12-17
I have been reading up on XSLT.
I understand its possible to extend XSLT to help get the result you need from the transform

I cant seem to find anywhere though that expains how you would call the class in teh XSLT to perform the required function.

Anyone familiar with this method that can help me understand it, and put it into action

Thanks
0
Comment
Question by:QuinnDester
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Gary Davis
ID: 24831298
Here's an example with two class static functions that can be called from within the xslt. There is also one variable that is set using a call to the Mixed() function.
Gary Davis
 

<?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" exclude-result-prefixes="msxsl"
	xmlns:AECScript="urn:my-scripts">
	<msxsl:script language="C#" implements-prefix="AECScript">
		<msxsl:assembly name="System.Web" />
		<msxsl:assembly name="AEC.2" />
		<msxsl:using namespace="AEC" />
		<![CDATA[
			public string Mixed(string s) {
				StrMixed strMixed = new StrMixed();
				return (strMixed.Mixed(s));
			}
			
			public string UPCCheckChar(string s) {
				return (AECLib.UPCCheckChar(s));
			}
		]]>
	</msxsl:script>
 
	<xsl:output method="html" encoding="utf-8" indent = "yes" />
	<xsl:variable name="ItemTitle" select="AECScript:Mixed(//Item/title)" />
    :
    :
    :
 
 
This is the classlibrary:
 
namespace AEC
{
    public class StrMixed
        {
            public StrMixed()
            {
                :
                :
                :
            }
        }
    }
}

Open in new window

0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24831816
so are these classes with in C# , That you have created or are they built in function of C#.

if i wanted to do something like this, would i just need to create a class that performs the action i want and then call it from the XSL

I have just been reading something about having to include the instruction in the XsltArgumentList, but i am struggling to get my head around it.
0
 
LVL 18

Assisted Solution

by:Gary Davis
Gary Davis earned 200 total points
ID: 24831922
In this case, I created these but you could call built in ones also like to perhaps, call UrlEncode().
You can pass parameters to the xslt using XsltArgumentList like this:

XsltArgumentList xal = new XsltArgumentList(); // Parameters for the xsl file
xal.AddParam("parm1", "", "some data");
xal.AddParam("parm2", "", "more data");
 
XslCompiledTransform tr = new XslCompiledTransform(false);
XsltSettings xsltSettings = new XsltSettings(true, true); // Assume trusted xslt
tr.Load(sXslFile, xsltSettings, null);
StringWriter sw = new StringWriter();
tr.Transform(xPathNavigator, xal, sw);
Then, in the xslt, you can pick up the parameters:
<xsl:param name="parm1" />
<xsl:param name="parm2" />
Gary Davis
0
 
LVL 3

Accepted Solution

by:
QuinnDester earned 0 total points
ID: 24835515
the conclusion of this question is in another question  see:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_24562199.html

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question