我试图清理XML文件与XSL转换。 当我直接将我的XSL我的XML文件,它工作正常。 但现在我要清理所有的XML文件我有一个目录。 我试图创建一个PowerShell脚本,加载和转换XML文件。
这里是我的代码:
$dir = "C:\MyDirectory"
$XSLFileName = "XSLTFile.xsl"
$XSLFileInput = $dir + $XSLFileName
$XMLFileName = "Input.xml"
$XMLInputFile = $dir + $XMLFileName
$OutPutFileName = "Output.xml"
$XMLOutputFile = $dir + $OutPutFileName
cd $dir
$XSLInputElement = New-Object System.Xml.Xsl.XslCompiledTransform;
$XSLInputElement.Load($XSLFileInput)
$XMLInputDoc = Get-Content -Path $XMLInputFile
$reader = [System.Xml.XmlReader]::Create($XMLInputFile)
$writter = [System.Xml.XmlTextWriter]::Create($XMLOutputFile)
$XSLInputElement.Transform($XMLInputDoc, $writter)
我已经扔了一些文档和SO科目找到如何使用Transform()
方法,但我还没有找到如何处理此错误:
Exception calling "Transform" with "2" argument(s): "Caractères non conformes dans le chemin d'accès."
At C:\ScirptsDirs\StackOverFlowTransformExample.ps1:20 char:1
+ $XSLInputElement.Transform($XMLInputDoc, $writter)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
注:“路径不兼容的字符。” 是指:在访问路径发现无效标志。
我想要做的就是清理我的XML文件,并创建一个其他的XML文件,但适用于它的XSL转换。
编辑:我也试过这种方式,因为马丁说:
$XSLInputElement.Transform($XMLInputFile, $XMLOutputFile)
但是这一次,我有你出现以下错误:
Exception calling "Transform" with "2" argument(s): "Execution of the 'document()' function was prohibited. Use the XsltSettings.EnableDocumentFunction property to enable it. An error occurred at D:\MyDirectory\XSLTFile.xsl(220,3)."
At C:\ScirptsDirs\StackOverFlowTransformExample.ps1:20 char:1
+ $XSLInputElement.Transform($XMLInputFile, $XMLOutputFile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : XslTransformException