Link to home
Start Free TrialLog in
Avatar of QuinnDester
QuinnDesterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

extending XSLT using C# classes

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
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

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

Avatar of QuinnDester

ASKER

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.
SOLUTION
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial