You cannot directly pass the Xslt string to the load method of the XslCompiledTransform class as there is no overloaded method for accepting the xslt string.
You can refer to the following sample for loading the xslt string.
Bonecrusher, yes I am using XslCompiledTransform, I noticed as well the mention of deprecation in the intellisense... so I changed my code there. However I needed to be able to load in code generated xslt instead of a file. Ksridharbabuus' may be the answer
I need. thanks!
Be sure to mark as answer if this post helped you.
Bonecrusher, yes I am using XslCompiledTransform, I noticed as well the mention of deprecation in the intellisense... so I changed my code there. However I needed to be able to load in code generated xslt instead of a file. Ksridharbabuus' may be the answer
I need. thanks!
Understood, however if you had read the links (msdn library) you would have derived at the same solution (and maybe learn a little at the same time [:D] )
Glad you got it working
Bones,
If I was helpful, please mark "answered" so I can get credit. Thanks!
Bonecrusher, yes I am using XslCompiledTransform, I noticed as well the mention of deprecation in the intellisense... so I changed my code there. However I needed to be able to load in code generated xslt instead of a file. Ksridharbabuus' may be the answer
I need. thanks!
Understood, however if you had read the links (msdn library) you would have derived at the same solution (and maybe learn a little at the same time )
Glad you got it working
Bones,
Actually I had read both MSDN arcticles and tried to derive using XmlReader in the load method, but it didnt work. None of the overload methods shown in the list would have led me to the same solution. At most I would have spent more time experimenting
(as I already had) to come up with something. Or rather it wasnt readily apparant.
Nothing like learning experiences :o)
Cheers!
Be sure to mark as answer if this post helped you.
1. Your answer was incorrect - there is no overloaded constructor that accepts a string. There is one in the load method, but that's for the path of the XSLT stylesheet not the markup inside it!
Your repeated statements that this is correct are just crazy and show a complete lack of understanding.
2. It's "arrived" not "derived"
Suggest you read things more carefully in future and learn syntax and how to read help before reading the riot act to somebody else!!
kevison
Member
81 Points
93 Posts
how do i load xlt string into XslTransform object
Dec 10, 2008 07:37 PM|LINK
I am creating an xslt transform and create it in code so I dont have to mess with files. however I cant get the load method to take it:
XslTransform xXslt = new XslTransform();string sXslt = BuildXLST();xXslt.Load(sXslt);
This doesnt work... my question becomes how can I load my code created xslt string?
Thnks
Bonekrusher
Contributor
4027 Points
922 Posts
Re: how do i load xlt string into XslTransform object
Dec 10, 2008 07:57 PM|LINK
What doesnt work? What is the error? The XslCompiledTransform.load constructor will handle a string.
Use XslCompiledTransform().
http://msdn.microsoft.com/en-us/library/ms163423.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspx
kevison
Member
81 Points
93 Posts
Re: how do i load xlt string into XslTransform object
Dec 10, 2008 08:15 PM|LINK
when it tries to load the string it throws {"Illegal characters in path."}
the contents of the string variable is:
<?xml version='1.0' encoding='UTF-8'?><xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/><xsl:template match='/'> <head><title>Error Output</title><body><h1><xsl:value-of select='Application' /> - Error</h1><table><tr><td>Method:</td><td><xsl:value-of select='Method' /></td></tr><tr><td>Message:</td><td><xsl:value-of select='Message' /></td></tr><tr><td>Trace:</td><td><xsl:value-of select='Trace' /></td></tr></table></body></head></xsl:template></xsl:stylesheet>
ksridharbabu...
Star
9239 Points
1356 Posts
Re: how do i load xlt string into XslTransform object
Dec 11, 2008 09:40 AM|LINK
Hi,
You cannot directly pass the Xslt string to the load method of the XslCompiledTransform class as there is no overloaded method for accepting the xslt string.
You can refer to the following sample for loading the xslt string.
public static void sample84()
{
string sXslt = "<?xml version='1.0' encoding='UTF-8'?><xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/><xsl:template match='/'> <head><title>Error Output</title><body><h1><xsl:value-of select='Application' /> - Error</h1><table><tr><td>Method:</td><td><xsl:value-of select='Method' /></td></tr><tr><td>Message:</td><td><xsl:value-of select='Message' /></td></tr><tr><td>Trace:</td><td><xsl:value-of select='Trace' /></td></tr></table></body></head></xsl:template></xsl:stylesheet>";
XslCompiledTransform objXslTrans = new XslCompiledTransform();
objXslTrans.Load(new XmlTextReader(new StringReader(sXslt)));
Console.WriteLine("Loaded");
}
Please note that the error message in your sample, is expecting path of the xslt file not the xslt string.
Hope this is what you are looking for.
Visit My Blog
-------------------------------------------------
If this post was useful to you, please mark it as answer. Thank you!
Bonekrusher
Contributor
4027 Points
922 Posts
Re: how do i load xlt string into XslTransform object
Dec 11, 2008 12:01 PM|LINK
Kevison,
Did you read my post (and repeated by ksridharbabuus).
Use XslCompiledTransform()
kevison
Member
81 Points
93 Posts
Re: how do i load xlt string into XslTransform object
Dec 11, 2008 12:38 PM|LINK
Bonecrusher, yes I am using XslCompiledTransform, I noticed as well the mention of deprecation in the intellisense... so I changed my code there. However I needed to be able to load in code generated xslt instead of a file. Ksridharbabuus' may be the answer I need. thanks!
Bonekrusher
Contributor
4027 Points
922 Posts
Re: how do i load xlt string into XslTransform object
Dec 11, 2008 12:56 PM|LINK
Understood, however if you had read the links (msdn library) you would have derived at the same solution (and maybe learn a little at the same time [:D] )
Glad you got it working
Bones,
kevison
Member
81 Points
93 Posts
Re: how do i load xlt string into XslTransform object
Dec 11, 2008 02:25 PM|LINK
Actually I had read both MSDN arcticles and tried to derive using XmlReader in the load method, but it didnt work. None of the overload methods shown in the list would have led me to the same solution. At most I would have spent more time experimenting (as I already had) to come up with something. Or rather it wasnt readily apparant.
Nothing like learning experiences :o)
Cheers!
giles.hinton
Member
108 Points
32 Posts
Re: how do i load xlt string into XslTransform object
Apr 22, 2010 09:05 AM|LINK
An old post, but two things -
1. Your answer was incorrect - there is no overloaded constructor that accepts a string. There is one in the load method, but that's for the path of the XSLT stylesheet not the markup inside it!
Your repeated statements that this is correct are just crazy and show a complete lack of understanding.
2. It's "arrived" not "derived"
Suggest you read things more carefully in future and learn syntax and how to read help before reading the riot act to somebody else!!
ehalsey
Member
2 Points
1 Post
Re: how do i load xlt string into XslTransform object
Jan 05, 2012 08:20 PM|LINK
Here's how to do it. Derived from http://forums.asp.net/t/1092511.aspx/1
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(xsltInput);
MemoryStream ms = new MemoryStream(bytes);
XmlReader reader = XmlReader.Create(ms);
xslEmailTransform.Load(reader);