Solved

extending XSLT using C# classes

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now