title: Applying XSL to XML with PowerShell : Exception calling "Transform"
body: <p>I'm trying to clean XML Files with an XSL Transformation. When I'm applying my XSL directly to my XML File, it works fine. But now I want to clean every XML File I have in a directory. I've tried to create a PowerShell script, to load and transform XML Files. </p>
  
  <p>Here is my code : </p>
  
  <pre><code>$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)
  </code></pre>
  
  <p>I've been threw some docs and SO subjects to find how to use the <code>Transform()</code> method, but I haven't found how to deal with this error : </p>
  
  <pre><code>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
  </code></pre>
  
  <blockquote>
    <p>Note : "Caractères non conformes dans le chemin d'accès." means :
    Invalid symbol found in the access path.</p>
  </blockquote>
  
  <p>What I want to do is to clean my XML File, and to create an other XML File but with the XSL Transformation applied to it. </p>
  
  <p><strong>EDIT :</strong> I've also tried this way, as Martin said : </p>
  
  <pre><code>$XSLInputElement.Transform($XMLInputFile, $XMLOutputFile)
  </code></pre>
  
  <p>But this time, I have thee following error : </p>
  
  <pre><code>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
  </code></pre>