Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

programmatically generate xsl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
skidz - 05 May 2005 06:29 GMT
I am trying to write an application that will generate XSL files
(trying to automat some of my development), but am having a heck of a
time. I just don't fully grasp the namespace issues I am having.

This is what I have so far:
---------------------------------Code
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration
("1.0","UTF-8", string.Empty));
XmlNode root = doc.AppendChild(doc.CreateElement
("xsl:stylesheet","http://www.w3.org/1999/XSL/Transform"));
XmlAttribute attr = doc.CreateAttribute("version");
attr.InnerText = "1.0";
root.Attributes.Append(attr);
---------------------------------/Code

That results into this:
---------------------------------Results
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>
----------------------------------/Results

Not to bad, but I run into problems here:
---------------------------------Code
root = root.AppendChild(doc.CreateElement
("xsl","template", "xsl"));
--------------------------------/Code

This gives me an element that looks like this:
---------------------------------Results
<xsl:template xmlns:xsl="xsl"/>
---------------------------------/Results

Am I doing this correctly? That 'xmlns:xsl="xsl"' I don't want there.
But if I try other combination of values (("xsl","template") ||
("xsl:template") || ("xsl","template","")) I never get the
"xsl:template", just "template".
Am I making sense?

Is there a better, or right why to do something like this (Besides
string builder)?  What am I doing wrong?

To the one that helps me with this problem I will give you an invisible
ring of +6 save against coding errors. (ooooo, awwwww)
Dmytro Lapshyn [MVP] - 05 May 2005 08:31 GMT
Hi,

You need to specify the URI of the 'xsl' namespace in the third argument of
CreateElement.
That is,

root = root.AppendChild(doc.CreateElement
   ("xsl","template", "http://www.w3.org/1999/XSL/Transform"));

Signature

Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]

>I am trying to write an application that will generate XSL files
> (trying to automat some of my development), but am having a heck of a
[quoted text clipped - 42 lines]
> To the one that helps me with this problem I will give you an invisible
> ring of +6 save against coding errors. (ooooo, awwwww)
Dimitre Novatchev - 05 May 2005 10:56 GMT
This is quite masochistic compared to generating xslt stylesheets using ...
XSLT.

Cheers,
Dimitre Novatchev.

>I am trying to write an application that will generate XSL files
> (trying to automat some of my development), but am having a heck of a
[quoted text clipped - 42 lines]
> To the one that helps me with this problem I will give you an invisible
> ring of +6 save against coding errors. (ooooo, awwwww)
skidz - 05 May 2005 18:47 GMT
Dmytro Lapshyn, Thx I will give that a try. I will email you the ring
as soon as I find it. :)

Dimitre Novatchev, I thought about doing that, but how do you escape
the xsl nodes you want to output, so they are not executed in the
transformation? I have never tried it so if the question is stupid you
have my permission to slap me.
Dimitre Novatchev - 06 May 2005 12:12 GMT
> Dmytro Lapshyn, Thx I will give that a try. I will email you the ring
> as soon as I find it. :)
[quoted text clipped - 3 lines]
> transformation? I have never tried it so if the question is stupid you
> have my permission to slap me.

No the question is not stupid.

Read about the

    "xsl:namespace-alias"

element.

Cheers,
Dimitre Novatchev
skidz - 06 May 2005 16:23 GMT
Dimitre Novatchev, That is perfect. I tried searching google for xsl to
xsl and could never find anything good. Thx
I can now stop being so masochistic.

Dmytro Lapshyn, your solution worked great also.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.