Connecting Tech Pros Worldwide Help | Site Map

Outputting ASP.NET tags using XSLT

Kathleen Dollard
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi,

Oleg's answer about attribute value templates led me to look back at a
different problem, and wonder if someone else had solved it.

I want to output an ASP.NET page. Thus I need to output ASP.NET tags and
HTML tags.

<%@ Page Language= etc...

and
<HTML> etc.

OK, so I use html output and can't get the directive output. <% gives an
error and &lt;% outputs exactly that which Visual Studio (at least) fails to
regonize.

So I use text output, and can get the page directive output correctly using
&lt;%. However, I have to escape everysingle < in the file, or the tag is
ignored and not output. It works, but man is it ugly.

A sample is below so you can point out any issues you see with it. The
garbage namespaces are from some messing around I was doing this morning on
the problem (it currently fails to output the HTML tags).
--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"



<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dbs="http://kadgen/DatabaseStructure"
xmlns:orm="http://kadgen.com/KADORM.xsd"
xmlns:ui="http://kadgen.com/UserInterface.xsd"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:net="http://kadgen.com/StandardNETSupport.xsd"
xmlns:asp="asdf"
xmlns:uc1="QWER"
xmlns=" HTMLSDFTUF">
<xsl:import href="webSupport.xslt"/>
<xsl:import href="../../Chapter 8/BusinessObjects/CSLASupport.xslt"/>
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:preserve-space elements="*" />

<xsl:param name="Name"/>
<xsl:param name="filename"/>
<xsl:param name="database"/>
<xsl:param name="gendatetime"/>
<xsl:param name="BusinessObject"/>

<xsl:variable name="projnamespace" select="//ui:UIRoot/@ProjectNamespace"/>
<xsl:variable name="objectname" select="$BusinessObject"/>
<xsl:variable name="objectsingular"
select="//orm:Object[@Name=$objectname]/@Name"/>

<xsl:template match="/">
<xsl:apply-templates select="//orm:Object[@Name=$objectname]"
mode="Object"/>
</xsl:template>

<xsl:template match="orm:Object" mode="Object">
&lt;%@ Page Language="vb" AutoEventWireup="false"
Codebehind="<xsl:value-of select="$objectsingular"/>Edit.aspx.vb"
Inherits="<xsl:value-of
select="concat($projnamespace,'.codebehind',
$objectsingular)"/>Edit"%>
&lt;%@ Register TagPrefix="uc1" TagName="Header" Src="..\..\Header.ascx" %>
<!--<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">-->
<HTML>
<HEAD>
<title><xsl:value-of select="$objectsingular"/>Edit</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"/>
<meta content="JavaScript" name="vs_defaultClientScript"/>
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"/>
</HEAD>
<body>
<form id="{$objectsingular}Edit"
method="post" runat="server">
<P>
<uc1:header id="Header1" runat="server">
</uc1:header>
</P>
<P>
<asp:label id="Label2"
runat="server" Font-Names="Bauhaus 93"
Font-Size="XX-Large">
Edit <xsl:value-of select="$objectsingular"/>
</asp:label></P>
</form>
</body>
</HTML>

</xsl:template>


</xsl:stylesheet>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="AssignmentEdit.aspx.vb"
Inherits="WebPTracker.codebehindAssignmentEdit"%>
<%@ Register TagPrefix="uc1" TagName="Header" Src="..\..\Header.ascx" %>
AssignmentEdit
Edit Assignment


Oleg Tkachenko
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


Kathleen Dollard wrote:
[color=blue]
> I want to output an ASP.NET page. Thus I need to output ASP.NET tags and
> HTML tags.[/color]

This is what disable-output-escaping feature was disagned to facilitate,
see http://www.w3.org/TR/xslt#disable-output-escaping.
disable-output-escaping feature is greately abused by people, but it's
primary goal is to allow to output nonXML/nonHTML formats, such as
ASP/JSP/XQuery/SQL/etc.
[color=blue]
> <%@ Page Language= etc...
>
> and
> <HTML> etc.
>
> OK, so I use html output and can't get the directive output. <% gives an
> error and &lt;% outputs exactly that which Visual Studio (at least) fails to
> regonize.[/color]

Try
<xsl:text disable-output-escaping="yes">&lt;%@ Page language="c#"
%></xsl:text>

This allows to output ASP tags while transforming using HTML or XML
output method.

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Dimitre Novatchev
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


Oleg Tkachenko <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message news:<OxMP1JJ0DHA.1684@TK2MSFTNGP12.phx.gbl>...[color=blue]
> Kathleen Dollard wrote:
>[color=green]
> > I want to output an ASP.NET page. Thus I need to output ASP.NET tags and
> > HTML tags.[/color]
>
> This is what disable-output-escaping feature was disagned to facilitate,
> see http://www.w3.org/TR/xslt#disable-output-escaping.
> disable-output-escaping feature is greately abused by people, but it's
> primary goal is to allow to output nonXML/nonHTML formats, such as
> ASP/JSP/XQuery/SQL/etc.[/color]

While Oleg is right about DOE, I'd recommend not to use DOE even in
such cases (as it may become a little bad habbit).

The attribute value: method="text" was intended for cases exactly like
this.

Certainly, one has to escape all "<" and "&" characters, but this will
help to never forget that the result is *not* a well-formed xml
document.

Another approach, which probably is the best compromise between
convenience and to using 100% conformant features of XSLT, is to use a
dummy namespace, bind the "asp" prefix to it, perform the
transformation and then update the result and remove the namespace
declaration.


Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
ampmeter
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


I gave got a similar problem as discussed, but I have added the recommendations to my code at it still does not work. Has anyone got a simple solution that they can share with me? i.e. just one user control returning XM

I would bery much appreciate any examples or references as this thing has been quite frustratin

Thankyou in advanced
Anas M. Nebuchadnezzar XXXVII
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


>>This is what disable-output-escaping feature was disagned to facilitate,[color=blue][color=green]
>>see http://www.w3.org/TR/xslt#disable-output-escaping.
>>disable-output-escaping feature is greately abused by people, but it's
>>primary goal is to allow to output nonXML/nonHTML formats, such as
>>ASP/JSP/XQuery/SQL/etc.[/color]
>
> While Oleg is right about DOE, I'd recommend not to use DOE even in
> such cases (as it may become a little bad habbit).
>
> The attribute value: method="text" was intended for cases exactly like
> this.
>
> Certainly, one has to escape all "<" and "&" characters, but this will
> help to never forget that the result is *not* a well-formed xml
> document.[/color]

I've run into a similar problem, that basically runs along the same
lines. I'm trying to use a FOR XML query with XmlDataDocument and I keep
getting.

<NewDataSet>
<Keywords>
<XML_F52E2B61-18A1-11d1-B105-00805F49916B>
&lt;nodeset&gt;
Nodeset with all special characters escaped.
&lt;/nodeset&gt;
</XML_F52E2B61-18A1-11d1-B105-00805F49916B>
</Keywords>
</NewDataSet>

Now, this may simply be a problem with how I'm doing it, but I still
think it might be usefull to have an easy way to convert these to their
character equivlents using XSL.
[color=blue]
> Another approach, which probably is the best compromise between
> convenience and to using 100% conformant features of XSLT, is to use a
> dummy namespace, bind the "asp" prefix to it, perform the
> transformation and then update the result and remove the namespace
> declaration.[/color]

Is there a schema for the asp: tags used with asp.net?

Dimitre Novatchev [MVP XML]
Guest
 
Posts: n/a
#6: Nov 12 '05

re: Outputting ASP.NET tags using XSLT



[color=blue]
> Is there a schema for the asp: tags used with asp.net?[/color]

AFAIK, there's no asp xml schema.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html




Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#7: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


Anas M. Nebuchadnezzar XXXVII wrote:
[color=blue]
> Is there a schema for the asp: tags used with asp.net?[/color]

ASP.NET syntax isn't XML, so I doubt there is a schema available.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Kevin Yu [MSFT]
Guest
 
Posts: n/a
#8: Nov 12 '05

re: Outputting ASP.NET tags using XSLT


Hi Andrew,

Have you tried to use the disable-output-escaping feature? Here is an
example:

<xsl:template match="description">
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dimitre Novatchev [MVP XML]
Guest
 
Posts: n/a
#9: Nov 12 '05

re: Outputting ASP.NET tags using XSLT



"Dimitre Novatchev [MVP XML]" <dnovatchev@yahoo.com> wrote in message
news:c216cb$1obb4u$1@ID-152440.news.uni-berlin.de...[color=blue]
>
>[color=green]
> > Is there a schema for the asp: tags used with asp.net?[/color]
>
> AFAIK, there's no asp xml schema.[/color]

And, of course, there cannot be one as ASP is not an application of XML.


Closed Thread