Using a custom class file in Umbraco XSLT

与世无争的帅哥 提交于 2019-12-08 03:52:57

问题


I'm trying to reference a custom class file in XSLT code. I deployed it as a DLL file to the /Bin directory.

Keep getting this error:

System.Xml.Xsl.XslTransformException: Cannot find the script or external object that implements prefix 'urn:sso'.

CS File Declarations:

namespace SSOUtilities
{
      public class sso

XSLT Reference:

<xsl:stylesheet 
version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:sso="urn:sso"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" 
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour sso">

config/xsltExtensions.config declaration:

<ext assembly="/bin/SSOUtilities" type="SSOUtilities.sso" alias="sso" />

回答1:


In Umbraco 4.5 you no longer need to put the /bin/ in the config/xsltExtensions.config declaration so this may be causing your error if you are using Umbraco 4.5.

http://our.umbraco.org/wiki/about/roadmap/umbraco-45/upgrading-to-umbraco-45




回答2:


Let me add another answer with a complete example of one of my extensions. The class Embed.cs:

using System.Web;
using umbraco.BusinessLogic;

namespace Omega.XsltExtensions
{
    public class Embed
    {
        public static void LogEmbed(int nodeId)
        {
            Log.Add(LogTypes.Open, new User(0), nodeId, "Embedded pano, referer: " + HttpContext.Current.Request.UrlReferrer);
        }
    }
}

This is being built as Omega.XsltExtensions.dll and copied to Umbraco's /bin directory.

In my xsltExtensions.config I've added:

<ext assembly="/bin/Omega.XsltExtensions" type="Omega.XsltExtensions.Embed" alias="Ext.Embed" />

An empty XSLT file that uses this extension looks 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:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
xmlns:Ext.Embed="urn:Ext.Embed"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Ext.Embed ">

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <xsl:template match="/">
      <xsl:value-of select="Ext.Embed:LogEmbed($currentPage/@id)"/>
  </xsl:template>

</xsl:stylesheet>

Hopefully you can spot any omissions in your version when you compare it to this one.




回答3:


You should add "sso" to your exclude-result-prefixes as well, the should make it work.

Also, your class should inherit from ApplicationBase and I'm not sure if a static class will work:

public class sso : ApplicationBase

And that is using umbraco.BusinessLogic if I'm not mistaken.




回答4:


It ended up being a syntax issue in the xsltExtensions.config

  <ext assembly="/bin/Umbraco.Forms.Core" type="Umbraco.Forms.Library" alias="umbraco.contour">
  <ext assembly="/bin/SSOUtilities" type="SSOUtilities.sso" alias="sso" />
  </ext>

Notice the closing tag which installing Contour placed in the file.



来源:https://stackoverflow.com/questions/3250286/using-a-custom-class-file-in-umbraco-xslt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!