471,075 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

System.Xml.Xsl.XslTransform and import node

Have a common function in Javascript which do transform for all .xsl's.
XSL object is loaded like this.

var xslobj=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0" );
xslobj.async = false;
xslobj.load(xslpath);

Here inserting an 'xsl:import' node to the xsl before doing transform.
This xsl contains some common templates which can be used across all xsl's.
So no need of doing import of this specifically in all xsl's.

var xslDoc = xslobj.documentElement;
var newNode =
xslobj.createNode(1,"xsl:import","http://www.w3.org/1999/XSL/Transform") ;
newNode.setAttribute ("href",server.mappath("common.xsl") ;
FirstChild=xslobj.documentElement.childNodes(0);
xslDoc.insertBefore(newNode, FirstChild);

This works fine in Javascript.

Now I'm trying to use the same logic in C Sharp.
Using System.Xml.Xsl.XslTransform for xsl.
Is it possible to do similar thing in C Sharp using
'System.Xml.Xsl.XslTransform' class.

I'm newbie to C Sharp.

thanks,

Praveen.

Jan 19 '07 #1
1 2784
Praveen wrote:
var xslDoc = xslobj.documentElement;
var newNode =
xslobj.createNode(1,"xsl:import","http://www.w3.org/1999/XSL/Transform") ;
newNode.setAttribute ("href",server.mappath("common.xsl") ;
FirstChild=xslobj.documentElement.childNodes(0);
xslDoc.insertBefore(newNode, FirstChild);

This works fine in Javascript.

Now I'm trying to use the same logic in C Sharp.
Using System.Xml.Xsl.XslTransform for xsl.
Is it possible to do similar thing in C Sharp using
'System.Xml.Xsl.XslTransform' class.
XslTransform is an XSLT processor, not a DOM document. If you want to
manipulate a stylesheet as a DOM document with .NET then you can use
System.Xml.XmlDocument e.g.

XmlDocument stylesheet = new XmlDocument();
stylesheet.Load(xslpath);
XmlElement xslImport = stylesheet.CreateElement("xsl:import",
stylesheet.DocumentElement.NamespaceURI);
xslImport.SetAttribute("href", Server.MapPath("common.xsl");
stylesheet.DocumentElement.InsertBefore(xslImport,
stylesheet.DocumentElement.FirstChild);

Then pass that stylesheet object to the Load method of an XslTransform
instance that takes an IXPathNavigable
<http://msdn2.microsoft.com/en-us/library/ms163479.aspx>

Also note that with .NET 2.0 the preferred XSLT implementation is
XslCompiledTransform, not XslTransform, which should only be used with
..NET 1.x.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Geir Sørensen | last post: by
10 posts views Thread by Vavel | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.