I am processing the XML result of a REST API call. I need to convert it to CSV. Based on this answer I could create a working example. However, this solution requires an XML Input file. A more elegant solution for me would be to be able to directly work with the XML result from the web request instead of having to store it first on my hard disk.
Hence, my question is: Is it possible to use the XSLT.Transform() function in Powershell with an XML object/variable instead of a XML file?
I already tried to pass the variable containing the XML to the function, but this yields an error.
My code looks like this:
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load("stylesheet.xslt");
$xslt.Transform($xmlResponse, "test.csv"); #$xmlResponse is of type XmlDocument
The execution of this code leads to a FileNotFoundException, because Powershell tries to resolve the variable $xmlResponse to a file path.