Skip to content

Instantly share code, notes, and snippets.

@wschwarz
Last active January 6, 2022 21:25
Show Gist options
  • Save wschwarz/5073004 to your computer and use it in GitHub Desktop.
Save wschwarz/5073004 to your computer and use it in GitHub Desktop.
Powershell script to run an xslt transform on a passed in file.
function process-XSLT
{param([string]$a)
$xsl = "C:\path_to_xslt\CleanUp.xslt"
$inputstream = new-object System.IO.MemoryStream
$xmlvar = new-object System.IO.StreamWriter($inputstream)
$xmlvar.Write("$a")
$xmlvar.Flush()
$inputstream.position = 0
$xml = new-object System.Xml.XmlTextReader($inputstream)
$output = New-Object System.IO.MemoryStream
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$arglist = new-object System.Xml.Xsl.XsltArgumentList
$reader = new-object System.IO.StreamReader($output)
$xslt.Load($xsl)
$xslt.Transform($xml, $arglist, $output)
$output.position = 0
$transformed = [string]$reader.ReadToEnd()
$reader.Close()
return $transformed
}
@LarsJohansson
Copy link

Hi, Much appreciated function, worked spotlessly the first time.
I have embedded the function in a script which I intend to license under GNU General Public License. Is that ok with you? In the script I remarked I found the function here.

function transXSL{param([string]$myxml,[string]$myxsl)

This XSL transform function found at https://gist.github.com/wschwarz/5073004

...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment