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
Solved

extending XSLT using C# classes

Posted on 2009-07-11
4
561 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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

808 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