.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 6th, 2004, 11:11 PM
awasson awasson is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 awasson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 40 sec
Reputation Power: 0
Parameter Values with the XML Control

Hey there,

I'm doing a complete overhaul of my site and at the same time will move it from ASP/MSDE to ASP.NET/SQL Server

Part of it will depend on a combination XML/XSL transform where the XSL file is passed a few parameters that are used in the parse. I can't seem to find the where and how of passing values to the XSL file using the XML control.

I've been using this technique with ASP for ages, and was really pleased with the simplicity of the XML control so far except for the parameter shortcoming.

Any ideas?

Thanks,
Andrew

Reply With Quote
  #2  
Old July 7th, 2004, 09:16 PM
awasson awasson is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 awasson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 40 sec
Reputation Power: 0
Well I'm back just in case someone was looking to do this, I have found a solution using code rather than the built in XML Control. The greater part of the code for this solution was thanks to Sonu Kapoor at the www.asp.net forums. I just massaged it into shape for my use.

It goes a bit like this:
(There's no error checking so an XSL or XML error will crash the page)

Code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.IO" %>
<%@ Page Language="C#" Debug="true" %>

<script  runat="server">
void Page_Load(object sender, System.EventArgs e){

    //Define the parameters
    string param1 = "PARAMETER 1";
    string param2 = "PARAMETER 2";

    if(!Page.IsPostBack){
        XmlDocument doc = new XmlDocument();
        doc.Load( Server.MapPath("~/xml/source.xml") );

        XslTransform xslt = new XslTransform(); 
        xslt.Load( Server.MapPath("~/xsl/stylesheet.xsl") );

        //ADD PARAMETER
        XsltArgumentList arglist = new XsltArgumentList();
        arglist.AddParam("param1", "", param1);
        arglist.AddParam("param2", "", param2);

        MemoryStream ms=new MemoryStream();
        xslt.Transform( doc, arglist, ms);
        ms.Seek( 0, SeekOrigin.Begin );

        StreamReader sr = new StreamReader(ms);

        //Apply the results to lblOutput
        lblOutput.Text = sr.ReadToEnd();
    }
}
</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>XML Test</title>
</head>
<body>
    <asp:Label ID="lblOutput" Runat="server"></asp:Label>

</body>
</html>


It's a bit more involved than using:
Code:
<asp:Xml 
ID="Xml1" 
Runat="server" 
DocumentSource="~/source.xml" 
TransformSource="~/stylesheet.xsl"> 
</asp:Xml> 


But... It lets you pass parameters to the stylesheet and provides all the more flexibility. I hope this helps someone else

Cheers,
Andrew

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Parameter Values with the XML Control


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT