Code Comments
Programming Forum and web based access to our favorite programming groups.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)
Post Follow-up to this messageHi,
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"));
--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"skidz" <robert.skidmore@gmail.com> wrote in message
news:1115270941.483975.315430@z14g2000cwz.googlegroups.com...
>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)
>
Post Follow-up to this messageThis is quite masochistic compared to generating xslt stylesheets using ...
XSLT.
Cheers,
Dimitre Novatchev.
"skidz" <robert.skidmore@gmail.com> wrote in message
news:1115270941.483975.315430@z14g2000cwz.googlegroups.com...
>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)
>
Post Follow-up to this messageHi,
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"));
--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"skidz" <robert.skidmore@gmail.com> wrote in message
news:1115270941.483975.315430@z14g2000cwz.googlegroups.com...
>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)
>
Post Follow-up to this message"skidz" <robert.skidmore@gmail.com> wrote in message news:1115315269.625721.282610@g14g2000cwa.googlegroups.com... > 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. No the question is not stupid. Read about the "xsl:namespace-alias" element. Cheers, Dimitre Novatchev
Post Follow-up to this messageDmytro 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.