[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Passing a Parameter to XSL from an ASPX page


Subject: RE: [xsl] Passing a Parameter to XSL from an ASPX page
From: Riju Abraham <R.Abraham@xxxxxxxxxxxx>
Date: Fri, 16 Jan 2004 11:15:36 +0300

 Hi,
   When I try to run this page I am getting an error 
  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
'CredentialCache' could not be found (are you missing a using   directive or
an assembly reference?)



 Does any one know abt the Namespace required ?

Riju

-----Original Message-----
From: M. David Peterson [mailto:m.david@xxxxxxxxxx]
Sent: Friday, January 16, 2004 10:26 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Passing a Parameter to XSL from an ASPX page


you are using classic ASP within an ASPX page which will work but you need
to specify this in your settings.  However, if youre already running on top
of .NET you might as well take advantage of the XSLTransform() method.  This
is MUCH more efficient than using the old MSXML stuff..  Heres a sample
using C#.

<%@ Page Trace="false" Language="C#" Debug="false" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.XPath" %>
<%@ import Namespace="System.Xml.Xsl" %>

<script runat="server">

void Page_Load(Object sender, EventArgs e){

        XsltArgumentList xslArg = new XsltArgumentList();
        xslArg.AddParam("nameOfParam", "", "valueOfParam");
        //continue adding parameters in this matter until your done

        //Create a resolver and set the credentials to use.
        //this gives you the ability to use things like the document()
function
        XmlUrlResolver resolver = new XmlUrlResolver();
        resolver.Credentials = CredentialCache.DefaultCredentials;

        // Load the XML document to transform.
        XPathDocument doc = new XPathDocument(Server.MapPath("test.xml"));

        // Load the stylesheet and perform the transform.
        XslTransform xslt = new XslTransform();

        xslt.Load(Server.MapPath(test.xslt));
        xslt.Transform(doc, xslArg, Response.OutputStream, resolver);
}

</script>

<html>
<head>
    <title/>
</head>
<body>
    <form runat=server>
    </form>
</body>
</html>

This should get you to where you want to go...

Best of luck!

M.



----- Original Message ----- 
From: "Riju Abraham" <R.Abraham@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, January 15, 2004 11:37 PM
Subject: [xsl] Passing a Parameter to XSL from an ASPX page


>
> Hi
>    Can some one help me with how to pass a parameter froom an aspx page to
> an xsl file to do the dynamic sorting .
> I have done it ..but I am not able to create the MSXML2.XSLTemplate.
> If I run the page I am getting the error "The xsltemplate object is null
or
> empty".
>
> Can some one help me out of this...
>
> Thanx in advance..
>
> ASPX Page
> --------------------------------------------------------------------------
--
> --------------------------------------
> <script language="javascript">
>
> var strXMLFileName,strXSLFileName;
> var objXMLDoc,objXSLDoc,objXSLTemplateNae;
> var currentSortDirection="ascending";
> var currentSortCol="";
> strXMLFileName="KSAArea.xml";
> strXSLFileName="KSAArea.xsl";
>
> function OnInitPage()
>  {
>   objXMLDoc = new ActiveXObject("MSXML2.DOMDocument");
> //objXMLDoc.async = false;
> //This is necessary to use XPath in selectSingleNode and selectNodes
> methods
> // For backwards compatibility, XSL Patterns are default.
> //objXMLDoc.setProperty("SelectionLanguage", "XPath");
> //objXMLDoc.resolveExternals = false;
> //objXMLDoc.validateOnParse = false;
> objXMLDoc.load(strXMLFileName);
> objXSLDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
>
> //objXSLDoc.async = false;
> //objXSLDoc.resolveExternals = false;
> //objXMLDoc.validateOnParse = false;
> objXSLDoc.load(strXSLFileName);
>
> window.alert(strXSLFileName);
> window.alert("Inside InitPage 1");
>       objXSLTemplate = new ActiveXObject("MSXML2.XSLTemplate");
>       //Here I am getting the ERROR .The OBJXSLTemplate object is NUll or
> empty..
>     window.alert("Inside InitPage 2");
> objXSLTemplate.stylesheet = objXSLDoc;
>     window.alert("Inside InitPage3");
>     ClickedMe("Area");
>     }
>
>  function ClickedMe(strSort)
>  {
>    var objXSLProcessor;
>    window.alert("UserClicked on 1 " + strSort);
>    objXSLProcessor=objXSLTemplate.createProcessor();
>    window.alert("UserClicked on 2 " + strSort);
>    objXSLProcessor.input=objXMLDoc;
>    window.alert("UserClicked on 3 " + strSort);
>    objXSLProcessor.addParameter("sortBy",strSort);
>    window.alert("UserClicked on 4 " + strSort);
>  }
>  window.onload=OnInitPage;
> </script>
>
> --------------------------------------------------------------------------
--
> --------------------------------
> The XSL FILE
>
> <xsl:transform version="1.0"
>     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
>     xmlns:msxsl ="urn:schemas-microsoft-com:xslt">
>     <xsl:output method="html"></xsl:output>
>     <xsl:param name ="sortBy">country</xsl:param>
>     <xsl:template match="/">
>     <html>
>     <body>
>     <div align ="left">
>      Sort By:
>        <xsl:value-of select="$sortBy"></xsl:value-of>
>     </div>
>     <table width="210" border="2pt" cellspacing="0" cellpadding="3"
> bordercolor="#dddddd" style="border-collapse:collapse;">
> <tr bgcolor="#9acd32">
> <th align="Left"><a class="clickanchor"
> onclick="ClickedMe('Country');" >Country</a></th>
> <th align="Left"><a class="clickanchor"
> onclick="ClickedMe('AreaCode');" >AreaCode</a></th>
> <th align="Left"><a class="clickanchor"
> onclick="ClickedMe('AreaDescription');">AreaDescription</a></th>
>
> </tr>
>
> <xsl:for-each  select ='locations/area'>
> <xsl:sort select="areadescription"/>
> <tr>
> <td class="Normal">
> <center>
> <xsl:value-of select ='country'/>
> </center>
> </td>
> <td class="Normal">
> <center>
> <xsl:value-of select ='areacode'/>
> </center>
> </td>
> <td class="Normal">
> <left>
> <xsl:value-of select
> ='areadescription'/>
> </left>
> </td>
> </tr>
> </xsl:for-each>
>       </table>
>       </body>
>       </html>
>       </xsl:template>
> </xsl:transform>
>
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords