Je retourne XML à partir d'un contrôleur d'action en utilisant un ActionResult personnalisé:application XSLT XML dans Asp.NET MVC
public class XmlActionResult : ActionResult
{
/// <summary>
/// This class is a custom ActionResult that outputs the content of an XML document to the response stream
/// </summary>
private readonly XDocument _document;
public Formatting Formatting { get; set; }
public string MimeType { get; set; }
public XmlActionResult(XDocument document)
{
_document = document;
MimeType = "text/xml";
Formatting = Formatting.None;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = MimeType;
using(var writer = new XmlTextWriter(context.HttpContext.Response.OutputStream, null)
{
Formatting = Formatting
})
_document.WriteTo(writer);
}
}
Ce produit l'arbre XML au navigateur. J'ai un fichier XSL qui transforme le XML, comment j'appliquerais la feuille de style à la sortie XML?
Veuillez arrêter de vous référer à "ASP.NET MVC" simplement comme "MVC". L'un est un cadre, tandis que l'autre est un modèle de conception indépendant du langage. C'est comme appeler IE - "l'Internet" –
C'est un point juste, des excuses! –
Où souhaitez-vous appliquer la transformation XSLT - sur le serveur ou sur le navigateur client? –