Home > Archive > C# > May 2005 > programmatically generate xsl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
programmatically generate xsl
|
|
|
| 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] 2005-05-06, 3:58 pm |
| 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"));
--
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)
>
| |
| Dimitre Novatchev 2005-05-08, 8:57 pm |
| This 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)
>
| |
| Dmytro Lapshyn [MVP] 2005-05-09, 8:58 am |
| 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"));
--
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)
>
| |
| Dimitre Novatchev 2005-05-10, 3:58 pm |
|
"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
| |
|
| 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.
|
|
|
|
|