Last active
January 6, 2022 21:25
-
-
Save wschwarz/5073004 to your computer and use it in GitHub Desktop.
Powershell script to run an xslt transform on a passed in file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
...
}