473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2895
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
1
by: Ronald | last post by:
I just wrote some code on a dev machine, Imports System.Xml Imports System.Xml.XPath Imports System.Xml.Xsl Imports System.IO Imports System.Data.SqlClient Public Class ClassXMLtoHTML Dim...
1
by: Geir Sørensen | last post by:
Hi, When I transform an xml-file using XslTransform, I seem to get a lot of elements of this form: <a> </a> <b> </b> But I really would like to get written out like I do when transforming...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
4
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt...
3
by: Eugen Gulinsky | last post by:
Hello guys, I am having problems trying to migrate our MSXML4-compatible stylesheets containing large msxsl:script blocks to a formate understandable by System.Xml:Xsl.XslTransform. I keep...
10
by: Vavel | last post by:
Hi all! I want to insert the record into the table by using an application program that includes the following statements: EXEC SQL BEGIN DECLARE SECTION; long hvInt_Stor; long hvExt_Stor;...
1
by: Luis Esteban Valencia | last post by:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.