Solved

extending XSLT using C# classes

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

689 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