Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 2nd, 2008, 10:54 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default HELP: XML/XSLT/ASP.NET Calendar Control

Can someone give me the basics or point me in the right direction on how I can create an ASP.NET calendar control within a XML/XSLT transformation? I'd really appreciate any help. Thanks.

KWilliams
  #2 (permalink)  
Old May 2nd, 2008, 02:05 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="http://microsoft.com/2005/aspnet">

<asp:Calendar runat="server" />

</xsl:stylesheet>

/- Sam Judson : Wrox Technical Editor -/
  #3 (permalink)  
Old May 3rd, 2008, 03:24 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

XSLT takes input, usually XML and outputs a differently formatted file. If you show your input and desired output then we can probably help. There is nothing special about creating an ASP calendar control as opposed to creating a COBOL data record.
Having said that producing ASP.NET files does have some inherent difficulties, the files are pseudo-XML at best so you often need to use the text output directive.

I have asked Microsoft if it is possible to have a pure XML representation of ASP.NET files whereby such constructs as <%# %> are replaced by elements such as <asp:BindingData/>. Don't hold your breath.

--

Joe (Microsoft MVP - XML)
  #4 (permalink)  
Old May 5th, 2008, 09:38 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

samjudson:

I tried your suggestion, but nothing showed up on the page. When I looked at the source code, this is what I saw:
<asp:Calendar runat="server" xmlns:asp="http://microsoft.com/2005/aspnet" />
<br xmlns:asp="http://microsoft.com/2005/aspnet" />

I also tried using xmlns:asp="remove" instead of xmlns:asp="http://microsoft.com/2005/aspnet" per the suggestion of others, but that had a similar non-working result:
<asp:Calendar runat="server" xmlns:asp="remove" />
<br xmlns:asp="remove" />

***********************************
joefawcett:

Thanks for the info. Per your suggestion, here's three different XSLT stylesheets that I've tried without success:

XSLT doc #1:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <asp:Calendar runat="server" />
        <br />
    </xsl:template>
</xsl:stylesheet>
XSLT doc #2:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="http://microsoft.com/2005/aspnet">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <asp:Calendar runat="server" />
        <br />
    </xsl:template>
</xsl:stylesheet>
XSLT doc #3:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="http://microsoft.com/2005/aspnet">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <asp:Calendar runat="server" />
        <br />
    </xsl:template>
</xsl:stylesheet>
All three had the same result, which is noted in my response to samjudson above. I haven't tried to pull in the data that I have in the XML doc, as I'm just trying to get the ASP.NET calendar to work in the first place.

***********************************

If anyone can let me know what I'm doing wrong, I'd very much appreciate it. Thanks.

KWilliams
  #5 (permalink)  
Old May 5th, 2008, 09:53 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Your stylesheet can create the asp:Calendar markup but you need to parse that markup then to have an ASP.NET server-side control. Are you doing that?
Code:
Page.Controls.Add(Page.ParseControl(stringWithTransformationResult));
--
  Martin Honnen
  Microsoft MVP - XML
  #6 (permalink)  
Old May 5th, 2008, 10:00 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Martin Honnen
 Your stylesheet can create the asp:Calendar markup but you need to parse that markup then to have an ASP.NET server-side control. Are you doing that?
Code:
Page.Controls.Add(Page.ParseControl(stringWithTransformationResult));
--
  Martin Honnen
  Microsoft MVP - XML
No I did not. I know that this is probably a stupid question, but I am pretty much a newbie to all of this, so I'll ask it: What exactly do I place in the space that you have labeled "stringWithTransformationResult"?

Thanks for your help:)

KWilliams
  #7 (permalink)  
Old May 5th, 2008, 10:17 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I assume you use ASP.NET and XslCompiledTransform to perform the XSLT transformation, you need to tranform to a string and parse that string result.
So assume your .aspx has a placeholder:
Code:
<asp:PlaceHolder ID="P1" runat="server"></asp:PlaceHolder>
and you want to place the Calendar in that placeholder then you can do that in the Page_Load method as follows:
Code:
        XslCompiledTransform proc = new XslCompiledTransform();
        proc.Load(Server.MapPath("XSLTFile1.xsl"));
        StringWriter writer = new StringWriter();
        proc.Transform(XmlReader.Create(Server.MapPath("XMLFile1.xml")), null, writer);
        P1.Controls.Add(Page.ParseControl(writer.ToString()));
--
  Martin Honnen
  Microsoft MVP - XML
  #8 (permalink)  
Old May 5th, 2008, 02:30 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For the site itself, I'm actually using a central MasterPage setup to handle all of the XML and XSL transformations throughout the site. So I'm using the ASP.NET DocumentSource Property to transform the XML/XSL docs, like this:

Code-behind for Master Page (MasterPage.master.vb):
Code:
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim strXMLPath_mc As String, strXSLPath_mc As String

        strXMLPath_mc = "docs/xml/events_calendar.xml"
            strXSLPath_mc = "docs/xslt/events_calendar.xsl"
            'Please Note: These 2 docs are actually dynamically produced using additional code, but I'm using the paths that are actually produced for this page for simplicity's sake.

        xslTransform_mc.DocumentSource = strXMLPath_mc
            xslTransform_mc.TransformSource = strXSLPath_mc
        End Sub
End Class
Master Page (MasterPage.master):
Code:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" Explicit="True" Debug="True" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
</head>
<body>
    <div id="content">
        <asp:Xml id="xslTransform_mc" runat="server"></asp:Xml>
    </div>
</body>
</html>
ASP.NET doc (events_calendar.aspx):
Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" EnableSessionState="false" EnableViewState="false" title="Events Calendar" %>
So with this setup, how do you suggest using Page.Controls.Add(Page.ParseControl(stringWithTran sformationResult))?

KWilliams
  #9 (permalink)  
Old May 6th, 2008, 05:44 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't think the ASP.NET Xml control helps if you want to use XSLT to create ASP.NET controls, it only allows you to generate HTML sent directly to the browser.

So you can't use the ASP.NET Xml control, instead you need to run the transformation as shown in my previous post. Put that code into your Page_Load handler and add the result to a control in your master page, for instance a place holder, as my example showed.

--
  Martin Honnen
  Microsoft MVP - XML
  #10 (permalink)  
Old May 6th, 2008, 09:02 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate the suggestion, but doesn't that defeat the whole purpose of using a XML/XSLT transformed site? Wouldn't that be handling everything on the ASP.NET side of things? If so, that won't work with my setup, as the XML/XSLT docs only contain data for the body of the document. I don't want an events calendar on every page, which is what would happen if I put it into a placeholder on the Master Page...correct?

KWilliams




Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Control in ASP.NET 2.0 midway11 ASP.NET 1.x and 2.0 Application Design 3 May 11th, 2007 05:26 PM
ASP.NET and XML/XSLT kwilliams ASP.NET 2.0 Basics 0 January 8th, 2007 01:03 PM
XML > XSLT and ASP.NET 2.0 bonekrusher XSLT 7 September 22nd, 2006 06:26 PM
ASP.NET Calendar Control Client Side Access rodmcleay ASP.NET 1.0 and 1.1 Basics 4 June 17th, 2005 11:45 PM
Calendar control for ASP.NET App mishi ASP.NET 1.x and 2.0 Application Design 2 April 10th, 2005 05:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.