在 Umbraco XSLT 中使用自定义类文件

发布于 2024-09-10 02:21:05 字数 1211 浏览 3 评论 0原文

我正在尝试在 XSLT 代码中引用自定义类文件。我将它作为 DLL 文件部署到 /Bin 目录。

继续出现此错误:

System.Xml.Xsl.XslTransformException:找不到实现前缀“urn:sso”的脚本或外部对象。

CS 文件声明:

namespace SSOUtilities
{
      public class sso

XSLT 参考:

<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 声明:

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

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" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

來不及說愛妳 2024-09-17 02:21:05

在 Umbraco 4.5 中,您不再需要将 /bin/ 放入 config/xsltExtensions.config 声明中,因此如果您使用 Umbraco 4.5,这可能会导致错误。

http://our.umbraco.org/ wiki/about/roadmap/umbraco-45/升级到-umbraco-45

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

凉城凉梦凉人心 2024-09-17 02:21:05

让我添加另一个答案,其中包含我的一个扩展的完整示例。 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);
        }
    }
}

它被构建为 Omega.XsltExtensions.dll 并复制到 Umbraco 的 /bin 目录。

在我的 xsltExtensions.config 中,我添加了:

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

使用此扩展的空 XSLT 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp " ">
]>
<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>

希望当您将其与此版本进行比较时,您可以发现您的版本中的任何遗漏。

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 " ">
]>
<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.

静赏你的温柔 2024-09-17 02:21:05

您还应该将“sso”添加到您的排除结果前缀中,这应该可以使其工作。

另外,你的类应该继承自ApplicationBase,我不确定静态类是否可以工作:

public class sso : ApplicationBase

如果我没有记错的话,那就是使用umbraco.BusinessLogic。

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.

捶死心动 2024-09-17 02:21:05

它最终成为 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>

请注意安装 Contour 时放置在文件中的结束标记。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文