How to display XSL-transformed XML in ASP.NET page? - asp.net

So far all the XML / XSLT I've worked with takes an XML document and transforms it to a standalone HTML webpage using an XSLT file.
In my web application, I'm using a web service to retrieve the XML document, which I need to render and make human-readable, and then insert that formatted content into a content placeholder in my master page.
The easiest way would be to append the XSLT to the retrieved XML file and link that to the content placeholder, but something tells me I can't just do that.
I took a look at these Stack Overflow pages, but they just want to render the straight XML whereas I want a transformed XML. Also, I need to be able to put it into my master page template.

This article shows how:
http://www.codeproject.com/Articles/37868/Beginners-Introduction-To-XSL-Transform-Rendering-XML-Data-using-XSL-Get-HTML-output.aspx
even if the spelling is as bad as mine...
Added
And here's another link that shows how, perhaps a bit more simply
http://www.aspfree.com/c/a/XML/Applying-XSLT-to-XML-Using-ASP.NET/2/

Related

display xml file in browser with asp.net

This may be simple, although i'm having some trouble finding a solution.
i create a sitemap for my website in an xml file.i display content of xml file in aspx file.
but i want display xmlfile not in aspx.
when i use response.redirect("sitemap.xml"),it shows tree but i want to show only all content in sequential not in tree.
like this:
content of xmlfile:
<t><t1 p="s1"></t1><t2 p="s2"></t2></t>
but i want address bar=sitemap.xml and show like this:
p=s1p=s2 .....
any idea?
Some browsers will respect XSL declarations at the top of xml files. If you have such a declaration at the top of your xml file like this:
<?xml-stylesheet type="text/xsl" href="YourTransform.xsl"?>
It will apply the transform specified allowing you to output the xml however you want. However, support is not universal.

Display FORMATTED XML

I am retrieving an XML document from a web service (UPS actually), and I can pull the information I need from the XML, but I can't get the XML to display in the XML format. I can get it to display in a label and literal, but its all ran together. The nodes aren't displaying. The nodes display in a text box control, but it still runs together (no brks)
Any idea how to take the XML document that i get from the service and display it just like it would if you open up an XML doc in IE?
Thanks
BTW... i have search all day for this and the only thing i could find is if i was displaying a static file, which i'm not. I also tried doing the stringbuilder/stringwriter, but no luck. I'm still pretty new at this stuff so i could be missing something.
HELP... PLEASE!
Try encompassing the XML in the
<pre>... your xml</pre>
tags.

Seeing html code in tooltips in asp.net

I am parsing web service xml and populating a treeview in asp.net. I'm trying to display one of the xml node attributes as a tooltip, but that attribute happens to sometimes have html tags in it. I know there seem to be some custom tooltip stuff out there, but I don't have the time or the experience to play with those yet. Is there no way to easily remove such code or translate it into the textual equivalent? I know I can replace br tags with environment.newline, but I don't want to have to do this for every conceivable html tag that might be embeded in the content!
The HTML Agilty Pack is an HTML parser that can read HTML fragments - you can do that and then read the InnerText property of the top node. The effect will be a textual version of the HTML.

Multi-lingual static content in ASP.NET

Is there a simple way of making the static content of an .aspx page multi-lingual? Resource files are nice for controls but it's quite hard and annoying to write big chunks of html in them. Any easier ways?
Make properties in resources files and use them, .NET automatically finds the correct resource file, also just make sure so that the property name is same in all the resource files, so it will replace the property value in .aspx page with the value in the resource file.
Don't code html markup in resource file, have the html markup in the .aspx page itself, just get the essential values from resource files.
Just to reiterate what Mahesh said: do NOT put markup in the resource files, just put the static content into them.
If you need to serve different views based on culture, consider doing something else. For example, if you're using MVC you could write a view engine that return the correct markup for each culture.
#ciscoheat what you say is correct, LOCALIZE control is the right thing to use for big chunk of data.

What is the best practice for using ASP.NET MVC to render lots of html or text files?

I have a lot of html pages, but I don't know how to display them through the asp.net mvc view.
I buid a view as my template and use asp.net mvc to insert html into the template and then render it.
But the question is that I must use FileStream to read the raw html-based files into memroy and then put it into view template, like ViewData["content"] = ???.
I just want to know if there are some other better ways to render static html files to the browser.
Did i describe the question clearly?
I guess you could do something like this:
using(var file = new StreamReader(htmlFileName))
{
return Content(file.ReadToEnd());
}
Note that the mime type automatically defaults to text/html, but you could optionally specify which mime type headers should be sent by supplying the type as an additional argument to the Content method.
I guess you also can point a iframe element from HTML to the target file url directly.
Alternatively you could write your own ActionResult that writes the contents of the file to Response.Output (could potentially avoid loading the entire file into memory at once albeit it might not be a big issue).

Resources