Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 37 of 37

Thread: xmlPackages calling app_code functions

  1. #1
    Beatniks is offline Member
    Join Date
    Feb 2007
    Location
    St Louis
    Posts
    40

    Default xmlPackages calling app_code functions

    Is there a way to put xmlPackage accessible functions in the app_code folder?

    Meaning, within an xmlPackage being able to use:
    <xsl:value-of select="aspdnsf:slugslug()"/>
    Where slugslug() is placed somehow within the app_code folder? This would be beneficial to those who don't want to "muck-up" the source code.

    I tried declaring the XSLTExtensionBase source code "partial" and putting part of it in the App_Code folder, but that didn't work. See below:

    inside the app_code folder:
    Code:
    namespace AspDotNetStorefrontCommon
    { 
    public partial  class XSLTExtensionBase
    {
        public virtual string slugslug()
        {
            return "this is my slugslug";
        }
     }
        
    }
    And in the actual source code:

    Code:
        public partial class XSLTExtensionBase
        {
         ... tons and tons of code...
        }

  2. #2
    Beatniks is offline Member
    Join Date
    Feb 2007
    Location
    St Louis
    Posts
    40

    Default

    GOT IT!!!

    The following shows how to add custom functions in your App_Code so they are available for consumption in XmlPackages. That way, your custom functions can be added without having to recompile the application and it keeps custom code out of the original source code.


    In the App_Code folder:
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    
    /// <summary>
    /// Summary description for MyCode
    /// </summary>
    ///
    namespace mynamespace
    { 
        public class slug
        {
    
            public  string getmylistbox()
            {
                return "<select id='Select1'> <option>hello</option></select> ";
            }
    
        }
    
    }
    In the Web.config file:

    Code:
    	<!-- Add your own custom XSLTExtensionObjects here -->
    		<xsltobjects defaultExtension="">
    			<extensions>
    				<clear/>
            <add name="myCustomFunctions" type="mynamespace.slug" namespace="urn:myFunctions" />
    			</extensions>
    		</xsltobjects>
    I haven't been able to figure out what the name attribute is for.

    Now, in the xmlPackage:
    Code:
    <?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">
          <xsl:output 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>
    Drop the test xmlPackage into the engine.aspx:
    Code:
    <%@ Page language="c#" Inherits="AspDotNetStorefront.engine" CodeFile="engine.aspx.cs" EnableEventValidation="false"%>
    <%@ Register TagPrefix="aspdnsf" TagName="XmlPackage"  src="XmlPackageControl.ascx" %>
    <html><head>
    <title title="engine" />
    </head>
    <body>
    <aspdnsf:XmlPackage id="Package1" PackageName="testXXX.xml.config" runat="server" EnforceDisclaimer="true" EnforcePassword="true" EnforceSubscription="true" AllowSEPropogation="true"/>
    </body>
    </html>
    And you get a listbox with a hello as the only option.
    Last edited by Beatniks; 07-10-2007 at 06:42 PM. Reason: slight edit

  3. #3
    DanV's Avatar
    DanV is offline Ursus arctos horribilis
    Join Date
    Apr 2006
    Posts
    1,568

    Default

    Rate up on this post, and a sticky to go with it Great information for the community here!

  4. #4
    Alkaline is offline Senior Member
    Join Date
    May 2006
    Posts
    459

    Default

    WAIT WAIT WAIT

    You mean to tell me If we have custome code that is being sent to the XSLT_xtentions base which originally required us to chop up the source code can happily be inside the App_code folder?

    So essentially we can have smooth and simple upgrades without having to modify the new source with every release?

    if so...


    YAY!!! I can stop paying my dev guy 150 for every upgrade

  5. #5
    Chad Bumstead is offline Junior Member
    Join Date
    Jul 2007
    Posts
    3

    Default Slight Modification

    Thank you for the tip!

    I found that I had to change part of the line in the XMLPackage:

    HTML Code:
    <xsl:stylesheet version="1.0" xmlns:mynamespace="urn:mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="urn:myFunctions" xmlns:aspdnsf="urn:aspdnsf"    exclude-result-prefixes="aspdnsf">
    I had to change xmlns:str to xmlns:myFunctions for it to work for me.

    BTW... Now, how do we get access to certain run-time properties like the current URL? I noticed that some functions in the aspdnf namespace seem to have access to more data than is passed in through their parameters. Is there a base class we can inherit from?

  6. #6
    fooster is offline Member
    Join Date
    Jan 2007
    Posts
    98

    Default

    Don't forget to include your namespace prefix in the exclude-result-prefixes to avoid them being output to your html- which would be a bit naff. Add any extra prefixes in a whitespace delimted list eg:

    C#/VB.NET Code:

    exclude
    -result-prefixes="aspdnsf mynamespace" 
    Ben

  7. #7
    kurtplace is offline Junior Member
    Join Date
    Dec 2007
    Posts
    1

    Default I am trying to use this but...

    I am trying to use this from an input element. Here is my xml package

    HTML Code:
    <?xml version="1.0" standalone="yes" ?>
    <package version="2.1" displayname="Reservations" debug="false" includeentityhelper="true">
      <PackageTransform>
        <xsl:stylesheet version="1.0" xmlns:APCustomCode="urn:APCustomCode" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:APWishListFunctions="urn:APWishListFunctions" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf APCustomCode">
        <xsl:output method="html" omit-xml-declaration="yes"/>
          <xsl:template match="/">
            <xsl:value-of select="APWishListFunctions:getmylistbox()" disable-output-escaping="yes" />
    				
            <input id="MoveAllToCartButton" type="button" value="Order Everything" onclick="APWishListFunctions:MoveAllToCartButton_Click"/>
            <!--this DIV is opened in reservationeventheader.xml.config-->
            <xsl:text disable-output-escaping="yes">
    					&lt;/div&gt;	
            </xsl:text>
          </xsl:template>
        </xsl:stylesheet>
      </PackageTransform>
    </package>

    What I am getting is that the function MoveAllToCartButton_Click is undefined.

    Here is my C# code.

    HTML Code:
    public void MoveAllToCartButton_Click(object sender, System.EventArgs e){
      //Response.Redirect("ShoppingCart.aspx");
    }
    As far as I can tell I have done everything as above and the xsl:value-of select="APWishListFunctions:getmylistbox()" does indeed work but the button does not.

    Can anyone help?

  8. #8
    Lean is offline Junior Member
    Join Date
    Nov 2007
    Posts
    5

    Question

    Hi all !

    It is feasible to replace:

    <queryparam paramname="@AffID" paramtype="runtime" requestparamname="AffiliateID" sqlDataType="int" defvalue="0" validationpattern="" />

    With something like...

    <queryparam paramname="@AffID" paramtype="runtime" requestparamname="AffiliateID" sqlDataType="int" defvalue="MyASPNETFunction()" validationpattern="" />

    ( From entity.grid.xml.config file )

    Thanks !!

  9. #9
    Shemeka is offline Senior Member
    Join Date
    May 2008
    Posts
    101

    Default Appcode Directory

    This may be a dumb question but where is the appcode directory for aspdnsf for DNN? I don't see a subfolder for it in the appcode directory where all the other modules are ...
    ----------------------------------------
    www.amazingfacts.org

  10. #10
    dabe is offline Junior Member
    Join Date
    Sep 2006
    Posts
    9

    Default

    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

  11. #11
    joelcalhoun is offline Junior Member
    Join Date
    May 2008
    Posts
    1

    Default Issues with XML format

    We had a lot of trouble implementing this in our installation.

    We found that if you had comments <!-- like this --> in the XML Package between <PackageTransform> and the opening <xsl:stylesheet> tag the XML package would give a:

    Exception=Object reference not set to an instance of an object.

    After removing the comment this worked great.

  12. #12
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default

    Just a quick note. The methods of generating dynamic script in xml as discussed in the Dynamic Server Controls - Part Duex thread is applicable to this topic.

    http://forums.aspdotnetstorefront.co...ad.php?t=11714

  13. #13
    Shemeka is offline Senior Member
    Join Date
    May 2008
    Posts
    101

    Question

    I keep getting the following error:

    XmlPackage Exception: Exception=Last Trace Point=[]. Cannot find the script or external object that implements prefix 'urn:myFunctions'.
    System.ArgumentException: Last Trace Point=[]. Cannot find the script or external object that implements prefix 'urn:myFunctions'. at AspDotNetStorefrontCommon.XmlPackage2.TransformStr ing() at AspDotNetStorefrontCommon.AppLogic.RunXmlPackage(X mlPackage2 p, Parser UseParser, Customer ThisCustomer, Int32 SkinID, Boolean ReplaceTokens, Boolean WriteExceptionMessage)

    has anyone else run into this? the code is in app_code but it can't find it. I'm somewhat of a noob with this xsl stuff so I'm sure I'm doing something wrong but I'm not sure what ... any help would be greatly appreciated.
    ----------------------------------------
    www.amazingfacts.org

  14. #14
    Jesse is offline Banned
    Join Date
    May 2008
    Posts
    1,329

    Default

    Have you added MyFunctions() to the extensions node in your web.config file as mentioned earlier in these posts?

  15. #15
    Shemeka is offline Senior Member
    Join Date
    May 2008
    Posts
    101

    Default Yes ...

    I added the following code to the web.config:

    HTML Code:
    <sectionGroup name="system.web">
          <section name="urlrewrites" type="ASPDNSF.URLRewriter.Rewriter,ASPDNSF.URLRewriter" requirePermission="false"/>
          <section name="XsltObjects" type="XsltObjects.ExtensionConfigurationHandler, XsltObjects" requirePermission="false"/>
        </sectionGroup>
    And then in system.web:
    HTML Code:
    <XsltObjects defaultExtension="">
          <extensions>
            <add name="myFunctions" type="mynamespace.slug" namespace="urn:myFunctions" />
          </extensions>
        </XsltObjects>
    Is this correct?
    ----------------------------------------
    www.amazingfacts.org

  16. #16
    toofast is offline Senior Member
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ, USA
    Posts
    239

    Default

    any idea why i'm getting the following error. do i have to call another assembly or something?

    Code:
     Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
    
    Compiler Error Message: CS0103: The name 'CommonLogic' does not exist in the current context
    
    Source Error:
    
    Line 48:         {
    Line 49:             if (ParamValue == null ||
    Line 50:                 !CommonLogic.IsInteger(ParamValue))
    Line 51:             {
    Line 52:                 ReportError(ParamName, ParamValue);

  17. #17
    Jesse is offline Banned
    Join Date
    May 2008
    Posts
    1,329

    Default

    CommonLogic is not a standalone class. It is a class in ASPDotNetStorefrontCommon.dll. Have you referenced this DLL prior to calling the common logic class? Have you added the "using" tag to inherit the namespace?

  18. #18
    toofast is offline Senior Member
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ, USA
    Posts
    239

    Default

    i'm calling all the following:

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;
    using System.Text.RegularExpressions;
    using AspDotNetStorefrontCommon;
    using System.Resources;
    Maybe i need to inherit XSLTExtensionBase like this:

    Code:
        
    public class myclass
        {
        Inherits XSLTExtensionBase;
    but when i do that, i get this error:

    Code:
     Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
    
    Compiler Error Message: CS0246: The type or namespace name 'Inherits' could not be found (are you missing a using directive or an assembly reference?)
    
    Source Error:
    
    Line 22:     public class myclass
    Line 23: 	{
    Line 24:     Inherits XSLTExtensionBase;
    Line 25: 
    Line 26:     public class InputValidator

  19. #19
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default

    If you are properly "using AspDotNetStorefrontCommon" and have a reference to that assembly in your project, there is no reason I see why you should not be able to access the static methods of CommonLogic.

  20. #20
    toofast is offline Senior Member
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ, USA
    Posts
    239

    Default

    ok, now i'm getting the following error:

    Code:
    XmlPackage Exception: Exception=Last Trace Point=[]. Extension object 'urn:aspdnsf' does not contain a matching 'SizeColorQtyOptionVertical' method that has 7 parameter(s).
    
    
    System.ArgumentException: Last Trace Point=[]. Extension object 'urn:aspdnsf' does not contain a matching 'SizeColorQtyOptionVertical' method that has 7 parameter(s).
    
    at AspDotNetStorefrontCommon.XmlPackage2.TransformString() at AspDotNetStorefrontCommon.AppLogic.RunXmlPackage(XmlPackage2 p, Parser UseParser, Customer ThisCustomer, Int32 SkinID, Boolean ReplaceTokens, Boolean WriteExceptionMessage)
    Here is the full code for myfunctions.cs:
    Code:
    // ------------------------------------------------------------------------------------------
    // Copyright AspDotNetStorefront.com, 1995-2007.  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. 
    // ------------------------------------------------------------------------------------------
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Xml;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    using System.IO;
    using System.Resources;
    using System.Globalization;
    using System.Reflection;
    using System.Data;
    using System.Configuration;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Threading;
    using System.Text;
    using System.Text.RegularExpressions;
    using AspDotNetStorefrontCommon;
    
    
    /// <summary>
    /// Summary description for MyCode
    /// </summary>
    ///
    namespace mynamespace
    { 
    	public class InputValidator
    	{
    		private String m_RoutineName = String.Empty;
    
    		public InputValidator(String RoutineName)
    		{
    			m_RoutineName = RoutineName;
    		}
    
    		private void ReportError(String ParamName, String ParamValue)
    		{
    			throw new Exception("Error Calling XSLTExtension Function " + m_RoutineName + ": Invalid value specified for " + ParamName + " (" + CommonLogic.IIF(ParamValue == null, "null", ParamValue) + ")");
    		}
    
    		public String ValidateString(String ParamName, String ParamValue)
    		{
    			if (ParamValue == null)
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			return ParamValue;
    			;
    		}
    
    		public int ValidateInt(String ParamName, String ParamValue)
    		{
    			if (ParamValue == null ||
    				!CommonLogic.IsInteger(ParamValue))
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			return Int32.Parse(ParamValue);
    			;
    		}
    
    		public Decimal ValidateDecimal(String ParamName, String ParamValue)
    		{
    			if (ParamValue == null ||
    				!CommonLogic.IsNumber(ParamValue))
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			return Localization.ParseDBDecimal(ParamValue);
    			;
    		}
    
    		public Double ValidateDouble(String ParamName, String ParamValue)
    		{
    			if (ParamValue == null ||
    				!CommonLogic.IsNumber(ParamValue))
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			return Localization.ParseDBDouble(ParamValue);
    			;
    		}
    
    		public bool ValidateBool(String ParamName, String ParamValue)
    		{
    			if (ParamValue == null)
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			ParamValue = ParamValue.ToUpperInvariant();
    			if (ParamValue == "TRUE" || ParamValue == "YES" ||
    				ParamValue == "1")
    			{
    				return true;
    			}
    			return false;
    		}
    
    		public DateTime ValidateDateTime(String ParamName, String ParamValue)
    		{
    			DateTime dt = DateTime.MinValue;
    			if (ParamValue == null)
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			try
    			{
    				dt = Localization.ParseDBDateTime(ParamValue);
    				;
    			}
    			catch
    			{
    				ReportError(ParamName, ParamValue);
    			}
    			return dt;
    		}
    	}
    
        public class keough
        {
            protected Customer m_ThisCustomer;
    
            //Public Methods
            public Customer ThisCustomer
            {
                get { return m_ThisCustomer; }
            }
    
            public virtual string SizeColorQtyOptionVertical(String sProductID, String sVariantID, string sColors, string sSizes)
            {
                return SizeColorQtyOptionVertical(sProductID, sVariantID, sColors, sSizes, "Color", "Size");
            }
    
            public virtual string SizeColorQtyOptionVertical(String sProductID, String sVariantID, string sColors, string sSizes, string sColorPrompt, string sSizePrompt)
            {
                return SizeColorQtyOptionVertical(sProductID, sVariantID, sColors, sSizes, "Color", "Size", "");
            }
    
            public virtual string SizeColorQtyOptionVertical(String sProductID, String sVariantID, string sColors, string sSizes, string sColorPrompt, string sSizePrompt, string sRestrictedQuantities)
            {
                InputValidator IV = new InputValidator("SizeColorQtyOptionVertical");
                int ProductID = IV.ValidateInt("ProductID", sProductID);
                int VariantID = IV.ValidateInt("VariantID", sVariantID);
                String RestrictedQuantities = IV.ValidateString("RestrictedQuantities", sRestrictedQuantities);
                String Colors = IV.ValidateString("Colors", sColors);
                String Sizes = IV.ValidateString("Sizes", sSizes);
                StringBuilder results = new StringBuilder("");
                String[] ColorsSplit = Colors.Split(',');
                String[] SizesSplit = Sizes.Split(',');
    
                sColorPrompt = CommonLogic.IIF(sColorPrompt.Length > 0, sColorPrompt, "Color");
                sSizePrompt = CommonLogic.IIF(sSizePrompt.Length > 0, sSizePrompt, "Size");
    
                String Prompt = sColorPrompt + "/" + sSizePrompt;
                if (Sizes.Length == 0 && Colors.Length == 0)
                {
                    Prompt = AppLogic.GetString("common.cs.78", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    results.Append(Prompt);
                    String FldName = ProductID.ToString() + "_" + VariantID.ToString() + "_" + 0.ToString() + "_" + 0.ToString();
                    if (RestrictedQuantities.Trim().Length == 0)
                    {
                        results.Append("<input name=\"Qty_" + FldName + "\" type=\"text\" size=\"3\" maxlength=\"3\">");
                    }
                    else
                    {
                        results.Append("<small>" + Prompt + "</small>");
                        results.Append("<select name=\"Qty_" + FldName + "\" id=\"Qty_" + FldName + "\" onChange=\"if(typeof(getShipping) == 'function'){getShipping()};\" size=\"1\">");
                        results.Append("<option value=\"\">" + AppLogic.GetString("admin.common.ddSelect", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</option>");
                        foreach (String s in RestrictedQuantities.Split(','))
                        {
                            if (s.Trim().Length != 0)
                            {
                                int Q = Localization.ParseUSInt(s.Trim());
                                results.Append("<option value=\"" + Q.ToString() + "\">" + Q.ToString() + "</option>");
                            }
                        }
                        results.Append("</select>&nbsp;");
                    }
                }
                else
                {
                    results.Append("<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" style=\"border-style: solid; border-color: #EEEEEE; border-width: 1px;\">\n");
                    results.Append("<tr>\n");
                    results.Append("<td valign=\"middle\" align=\"left\"><b>" + Prompt + "</b></td>\n");
                    for (int i = SizesSplit.GetLowerBound(0); i <= SizesSplit.GetUpperBound(0); i++)
                    {
                        results.Append("<td valign=\"middle\" align=\"center\">" + SizesSplit[i].Trim() + "</td>\n");
                    }
                    results.Append("</tr>\n");
                    for (int i = ColorsSplit.GetLowerBound(0); i <= ColorsSplit.GetUpperBound(0); i++)
                    {
                        results.Append("<tr>\n");
                        results.Append("<td valign=\"middle\" align=\"right\" >" + ColorsSplit[i].Trim() + "</td>\n");
                        for (int j = SizesSplit.GetLowerBound(0); j <= SizesSplit.GetUpperBound(0); j++)
                        {
                            results.Append("<td valign=\"middle\" align=\"center\">");
                            String FldName = ProductID.ToString() + "_" + VariantID.ToString() + "_" + i.ToString() + "_" + j.ToString();
                            results.Append("<input name=\"Qty_" + FldName + "\" type=\"text\" size=\"3\" maxlength=\"3\">");
                            results.Append("</td>\n");
                        }
                        results.Append("</tr>\n");
                    }
                    results.Append("</table>\n");
                }
    
    
                return results.ToString();
            }
    		
        }
    
    }
    and here is my xmlpackage:
    Code:
    <xsl:value-of select="aspdnsf:SizeColorQtyOptionVertical(ProductID, VariantID, '', Sizes, 'Sizes', ' ', RestrictedQuantities)" disable-output-escaping="yes" />
    all i'm trying to do is copy the 'SizeColorQtyOption' function from XSLTExtensionbase.cs and tweak it slightly.
    Last edited by toofast; 06-23-2008 at 09:12 AM.

  21. #21
    Jesse is offline Banned
    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

  22. #22
    toofast is offline Senior Member
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ, USA
    Posts
    239

    Default

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

  23. #23
    Neeraj is offline Junior Member
    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.

  24. #24
    unspokenchaos is offline Junior Member
    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.

  25. #25
    Jesse is offline Banned
    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.

  26. #26
    unspokenchaos is offline Junior Member
    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?

  27. #27
    Jeanne is offline Junior Member
    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

  28. #28
    travistubbs is offline Junior Member
    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

  29. #29
    McJoe is offline Member
    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;

  30. #30
    JustBen is offline Junior Member
    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)
            {
            }

  31. #31
    K&N is offline Junior Member
    Join Date
    Mar 2008
    Posts
    18

    Default xmlPackages calling app_code functions

    Hi,

    I know we have probably been over this before, but I am having a similar problem to unspokenchaos in January. I am using vb, but I getting the same error...

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

    Firstly I assume this should work with vb? (I am not a web programmer by trade).

    Secondly, it is probably something really dumb, I have been banging my head against a brick wall for a few hours and a second pair of eyes always helps so...

    Thirdly, I am on 7.1.0.0, I assume this will not be a problem?

    The end game is to get magiczoom working so I am planning to override LookUpProductImage, however at the moment I just want to the basics going...

    So new namespace file:

    Imports System
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Xml
    Imports System.Xml.XPath
    Imports System.Xml.Xsl
    Imports System.IO
    Imports System.Resources
    Imports System.Globalization
    Imports System.Reflection
    Imports System.Data
    Imports System.Configuration
    Imports System.Drawing
    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
    Imports System.Threading
    Imports System.Text
    Imports System.Text.RegularExpressions
    Imports AspDotNetStorefrontCommon

    '<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


    My webconfig update:

    <add name="myCustomFunctions" type="mynamespace.slug" namespace="urn:myFunctions" />

    My xml package:

    <?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>

    and then dropped into engine.aspx:

    <aspdnsf:XmlPackage id="Package1" PackageName="test.xml.config" runat="server" EnforceDisclaimer="true" EnforcePassword="true" EnforceSubscription="true" AllowSEPropogation="true" ReplaceTokens="true"/>


    I have basically copied the original guy in this post apart from the conversion to vb...

    Any advice would be great.

  32. #32
    yakatz is offline Member
    Join Date
    Jul 2008
    Location
    Could be anywhere between 60N-28N and 77W-36E
    Posts
    84

    Exclamation Please do a search before asking questions:

    Quote Originally Posted by K&N View Post
    XmlPackage Exception: Exception=Last Trace Point=[]. Cannot find the script or external object that implements prefix 'urn:myFunctions'.
    As I think I have mentioned before in these forums, this seems to be only a problem with the vb version.
    See http://forums.aspdotnetstorefront.co...6&postcount=49
    Using ASPDotNetStoreFront since Version 3
    Got Version 9.
    Almost ready to deploy MultiStore (final testing stages for the new FirstData gateway)
    Finally upgraded our server to 2008 R2.

  33. #33
    pizzle1983 is offline Junior Member
    Join Date
    Mar 2010
    Posts
    2

    Default Calling a UserControl from an XmlPackage

    Hi,

    After reading the start of this thread I've been able to call app_code functions within an xml package that will generate html, ideally though I would like to load a custom usercontrol from the xml package to do the html generation rather than a function within app_code.

    Is there a way to load user controls within an xml package?

    Thanks in advance.

  34. #34
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    Is there a way to load user controls within an xml package?
    Unfortunately, there is not.

  35. #35
    jr365 is offline Junior Member
    Join Date
    Feb 2011
    Posts
    2

    Default Use MEF with .net 4

    Sorry to resurrect this thread, but I would like to suggest that in .net 4 builds, the application uses mef instead of the manual web.config work.

    This would allows developers to drop any dll into the bin folder, and then call it from the xslt.

    No config


  36. #36
    jr365 is offline Junior Member
    Join Date
    Feb 2011
    Posts
    2

    Default Documented on Blog

    If anyone is looking for a full documentation, I wrote down on my blog what worked for me: (link)

    I was able to get an external dll working. No need to muck around in the app_code folder.
    Last edited by jr365; 02-17-2011 at 11:02 AM. Reason: spelling correction

  37. #37
    cengen is offline Member
    Join Date
    Mar 2009
    Posts
    78

    Red face Got this working in MultiStore 9.2.0.0

    Hope this helps someone else.

    It still works as of MS 9.2.0.0 ...

    I had a problem, but it turned out to be this (I don't know much about xsl):

    In my xmlpackage file, I had one node was embedded within another ( </add> is out of place - needed another </add> after <add name>)

    http://forums.aspdotnetstorefront.co...742#post112742

    But I followed Jeremiah Redekop's example:
    http://blogs.geniuscode.net/JeremiahRedekop/?p=401

    At one point I put in a support ticket, but the response was a) incorrect, and b) not helpful.

    Follow your dreams and believe in yourself, no one else will ....
    Last edited by cengen; 04-20-2012 at 10:19 AM.