I need to run a XSLT transformation using a PowerShell script that recursively for all the object *.xml:
- Load the file
- Transform it
- Save the output with the same file name in the same path.
I thought something like this
FolderToCheck = "MyFolder"
Get-ChildItem $FolderToCheck -Filter *.xml | ForEach-Object {
# declare Xslt script for transformation
[Xml]$Xslt_script = Get-content 'MyScript.xslt'
# read xml
$File = [xml](Get-Content $_.FullName)
# Run the transformation
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Load($Xslt_script)
$xslt.Transform($File,$File)
}
I'm always getting error
Exception calling "Transform" with "2" argument(s): "Could not find file 'C:\Users\gdiprima00\System.Xml.XmlDocument'." At line:9 char:1 + $xslt.Transform($File,$File) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FileNotFoundException
What is it wrong? Can you suggest what to amend?