By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Outputting ASP.NET tags using XSLT

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Kathleen Dollard wrote:
I want to output an ASP.NET page. Thus I need to output ASP.NET tags and
HTML tags.
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.
<%@ 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.


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
Nov 12 '05 #2

P: n/a
Oleg Tkachenko <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message news:<Ox**************@TK2MSFTNGP12.phx.gbl>...
Kathleen Dollard wrote:
I want to output an ASP.NET page. Thus I need to output ASP.NET tags and
HTML tags.


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.


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
Nov 12 '05 #3

P: n/a
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
Nov 12 '05 #4

P: n/a
>>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.
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.


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


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

Nov 12 '05 #5

P: n/a

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


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


Nov 12 '05 #6

P: n/a
Anas M. Nebuchadnezzar XXXVII wrote:
Is there a schema for the asp: tags used with asp.net?


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

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #7

P: n/a
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."

Nov 12 '05 #8

P: n/a

"Dimitre Novatchev [MVP XML]" <dn********@yahoo.com> wrote in message
news:c2*************@ID-152440.news.uni-berlin.de...

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


AFAIK, there's no asp xml schema.


And, of course, there cannot be one as ASP is not an application of XML.
Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.