?
Solved

extending XSLT using C# classes

Posted on 2009-07-11
4
Medium Priority
?
579 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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