Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dominik 711 posts 733 karma points
    May 06, 2011 @ 13:00
    dominik
    0

    Create own class library (c#) and use methods of them in xslt

    Hello,

    Is there any useful tutorial which shows how I can use some methods of an own class library in xslt?

    I found some examples but i cant get it work.

    What i´ve done:

    Create a class library in visual studio (with one method). Build it and put the dll into the /bin/ folder

    My xslt is looking like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:testFunction="urn:testFunction"
    exclude-result-prefixes="msxml umbraco.library testFunctino">
    <msxsl:script language="C#" implements-prefix="testFunction" />
    <xsl:template match="/">
          <div>            
              
              <xsl:value-of select="Class1:convertText('test')" disable-output-escaping="yes"/>
           
          </div>        
    </xsl:template>
    </xsl:stylesheet>

    Can someone please help?

    Everytime i try to use the xsltExtensions.config file i get also an error.

    I am using Umbraco 4.7

  • Rich Green 2246 posts 4008 karma points
    May 06, 2011 @ 13:23
  • Pasang Tamang 258 posts 458 karma points
    May 06, 2011 @ 13:26
  • dominik 711 posts 733 karma points
    May 06, 2011 @ 13:46
    dominik
    0

    Hi Rich,

    I just tryed it by using the following xslt but it still does not work

     

    version="1.0" encoding="UTF-8"?>
    xsl:stylesheet [ ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">
     

    <xsl:template match="/">
          <div>
    <xsl:value-of select="ps.Helpers:uploadFileSize('String filePath')" disable-output-escaping="yes"/>
             
          div>        
    xsl:template>

    xsl:stylesheet>

    i also copied the .cs file into App_Code

    Have i to use any new namespace declarations?

    Thanks

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 06, 2011 @ 13:49
    Tom Fulton
    1

    One more small tutorial from Tim's blog if you are using 4.6+: http://www.nibble.be/?p=95

    Basically all you have to do is decorate the class with [XsltExtension] and copy the DLL to /bin/.  Then when you create XSLT files the appropriate tags will be added at the top to make it work.

    -Tom

     

  • Rich Green 2246 posts 4008 karma points
    May 06, 2011 @ 13:49
    Rich Green
    0

    Edit: See Tom's post if you're using >=4.6

  • dominik 711 posts 733 karma points
    May 06, 2011 @ 14:04
    dominik
    0

    ok now it works,

    just one question what is

    RestExtensionMethod and RestExtension?
  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 06, 2011 @ 14:20
    Tom Fulton
    0

    RestExtensionMethod is for exposing your methods /base/ methods that work similar to a REST web service.  There's a little information in the wiki:  http://our.umbraco.org/wiki/reference/umbraco-base

    In the example in Tim's blog post, that would effectively create a base method that could be called by visiting:  yoursite.com/base/TestAlias/HelloWorld, and the output would be "Hello World".  They can return XML or strings and can accept parameters like /HelloWorld/param1/param2.

    -Tom

  • dominik 711 posts 733 karma points
    May 06, 2011 @ 14:50
    dominik
    0

    Ok now i have another question.

    I created a new class inside my .cs file but i am not able to select it inside umbraco. Only one class is available

    How can i use more than one class?

  • dominik 711 posts 733 karma points
    May 06, 2011 @ 14:57
    dominik
    0

    Ok i got it i have to put in the [XsltExtension] in top of each class

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies