I have a document loaded via XElement.Parse() and I need to apply a XSL transform to it. How would I go about doing this? The only way I know to do is with XPathDocument and I know no way to convert between the two other than XElement->String->StringReader->Stream->XPathDocument.
There must be a better way.
In a related question, what’s the best way to apply XPath to an XElement?
Why not use:
where
xelementis anXElement,xsltis anXslCompiledTransform,arglistis anXsltArgumentListandsomeTextWriteris aTextWriter?In other words, use this instance method:
XElement.CreateReader()Or, you can use:
Read more about the
CreateNavigator()extension method here and here.The last MSDN link contains a complete code example of an XSLT transformation.
Update: This additional question was asked:
There are different ways to evaluate an XPath expression over an
XNodeExtensions.XPathEvaluate()or
Extensions.XPathSelectElements()or
Extensions.XPathSelectElement()