Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 37

Thread: xmlPackages calling app_code functions

  1. #21
    Join Date
    May 2008
    Posts
    1,329

    Default

    Your MyFunctions.cs is not listed as namespace 'urn:aspdnsf'. You're still calling the methods from XSLTExtensionBase.cs

  2. #22
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ, USA
    Posts
    239

    Default

    ah, i'm an idiot. got it now, thanks!

  3. #23
    Join Date
    Oct 2008
    Posts
    1

    Default Unrecognized configuration section system.web/xsltobjects.

    Hi,
    When i try to register my custom xslt extension in web.config file. Can someone paste the exact syntax of the changes to be made in web.config for resistering custom xslt extensions for xmlPackage.

  4. #24
    Join Date
    Jan 2009
    Posts
    2

    Default VB version of this code

    I think I properly converted this code into vb. But when I run the code, I get the following error:

    XmlPackage Exception: Exception=Last Trace Point=[]. Cannot find the script or external object that implements prefix 'urn:myFunctions'.

    My gut says i'm missing some link between the xml and the vb.

    Much thanks in advance.

  5. #25
    Join Date
    May 2008
    Posts
    1,329

    Default

    You still have to add your function call to the XSLTExtensions node of your web.config, and declare the namespace in your package.

  6. #26
    Join Date
    Jan 2009
    Posts
    2

    Default I'm really not that smart....

    Ok, so my web.config xsltobject section is:

    <!-- Add your own custom XSLTExtensionObjects here-->
    <xsltobjects defaultExtension="">
    <extensions>
    <clear/>
    <add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code"></add>

    <!--Added on January 15th, 2009-->
    <add name="myCustomFunctions" namespace="urn:myFunctions" type="mynamespace.slug" ></add>
    </extensions>
    </xsltobjects>

    My xml package called usabb.xml.config is:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- ################################################## ################################################## ## -->
    <!-- Copyright AspDotNetStorefront.com, 1995-2006. All Rights Reserved. -->
    <!-- http://www.aspdotnetstorefront.com -->
    <!-- For details on this license please visit the product homepage at the URL above. -->
    <!-- THE ABOVE NOTICE MUST REMAIN INTACT. -->
    <!-- $Header: /v6.1/Web/XmlPackages/test.xml.config 1 12/30/05 2:33p Administrator $ -->
    <!-- ################################################## ################################################## ## -->
    <package version="2.1" displayname="Variants In Right Bar" allowengine="true" debug="true" includeentityhelper="true">
    <PackageTransform>
    <xsl:stylesheet version="1.0" xmlns:mynamespace="urn:mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myFunctions="urn:myFunctions" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
    <xslutput method="html" omit-xml-declaration="yes" />
    <xsl:template match="*">
    I AM HEAR!!!!

    <xsl:value-of select="myFunctions:getmylistbox()" disable-output-escaping="yes" />

    aspdnsf:GetMLValue(Name)
    </xsl:template>
    </xsl:stylesheet>
    </PackageTransform>
    </package>

    my app_code vb file called usabb_test.vb is:

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls


    '<summary>
    'Summary description for MyCode
    '</summary>

    Namespace mynamespace
    Public Class slug

    Public Function getmylistbox() As String
    Return "<select id='Select1'> <option>hello</option></select> "
    End Function
    End Class

    End Namespace

    What gives? What am I doing incorrectly?

  7. #27
    Join Date
    Feb 2009
    Posts
    3

    Default

    I followed all the following steps to add a custom function, my function compiles, but when I run it I get the following error-could not load type 'mynamespace.slug and pints me to the following line in showproduct.aspx.cs line 365
    using (Xmlpackage2 p=new XMLpackage2(m_xmlpackage, this customer, skinID, "", "entityName=" + etc etc. I am currently making modifications to the product.variantsIntableCondensed,xml.config, pulling in data from an addition database which works fine until I started added this function.

    I am calling the function with
    <xsl: value-of select="myfunctions:getmyMF(/root/Fcusaweb/Info/MF)" disable-output-escaping="yes"/>

    and my function is in the
    App_Code/CustomFunctions.cs and the function is
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    ///<summary>
    /// This code will take the Molecular formula and convert the numbers to subscripts
    ///</summary>
    ///
    namespace mynamespace
    {
    public class Slug
    {
    public string getmyMF(string MF)
    {
    string FixedMF=string.Empty;
    string result;
    //if ((MF).Length != 0)
    if (MF==null)
    {
    result = MF;
    return result;
    }
    else
    for (int i = 1; i <= MF.Length; i++)
    {

    if (char.IsDigit(MF[i]))
    {

    FixedMF = FixedMF + "<SUB>" + MF[i] + "</SUB>";
    }
    else
    {
    FixedMF = FixedMF + MF[i];

    }

    }
    return FixedMF;
    }

    }

    }

    I am new to this can someone help

  8. #28
    Join Date
    Apr 2009
    Location
    Houston, TX
    Posts
    8

    Question

    I need to be able to use ThisCustomer, but it appears the code that someone posted earlier is in VB and not C#. I've tried using VB to C# converters but keep getting errors.

    Anyone know how to implement the following in C# instead?

    Quote Originally Posted by dabe View Post
    Thought it might be useful to note that if you wish to use the 'ThisCustomer' object like you can do within XSLTExtensionBase then you should do the following:

    Code:
    Namespace Custom
        Public Class CustomXSLTExtensions
            Inherits XSLTExtensionBase
    
            'Constructor
            <Obsolete("This constructor has been deprecated and will be removed in a future version.  Use XSLTExtensionBase(Customer cust, int SkinID) instead")> _
            Public Sub New(ByVal cust As Customer, ByVal SkinID As Integer, ByVal EntityHelpers As Dictionary(Of String, EntityHelper))
                Me.New(cust, SkinID)
            End Sub
    
            Public Sub New(ByVal cust As Customer, ByVal SkinID As Integer)
                MyBase.New(cust, SkinID)
            End Sub
    
    ... YOUR CUSTOM FUNCTIONS HERE ...
    
        End Class
    End Namespace

  9. #29
    Join Date
    Oct 2007
    Posts
    50

    Default

    Quote Originally Posted by travistubbs View Post
    I need to be able to use ThisCustomer, but it appears the code that someone posted earlier is in VB and not C#. I've tried using VB to C# converters but keep getting errors.

    Anyone know how to implement the following in C# instead?

    above code doesn't work because when extending XSLTExtensionBase, there is no empty parameter constructor. When the extension method is instantiated, it is looking for a constructor with zero parameters.

    I used the code below to get the customer object, then set it to a global variable.

    Customer = ((AspDotNetStorefrontPrincipal)HttpContext.Current .User).ThisCustomer;

  10. #30
    Join Date
    Nov 2008
    Posts
    17

    Default

    This is some example code for how you would inherit from XSLTExtensionBase in C#


    Code:
    public class CellUpFunctions : XSLTExtensionBase

    Code:
            public CustomFunctions(Customer cust, int skin):base(cust, skin)
            { 
            }
    
            public CustomFunctions(Customer cust, int skin, Dictionary<string,EntityHelper> helpers): base(cust, skin)
            {
            }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •