Convert-Xml : Execution of the 'document()' function was prohibited

Topics: User Forum
Nov 18, 2014 at 10:24 PM
Edited Nov 18, 2014 at 10:28 PM

I'm passing an XSLT that has a variable loaded using document() from an external XML file but it fails with the prohibited error and suggests using the XsltSettings.EnableDocumentFunction property to enable it. Can anyone post a sample of code that would allow me to do that, or is it not possible with Convert-Xml? The transfom works as expected when executed in Visual Studio.

This is an example of what it chokes on :

<xsl:variable name="samples" select="document('Input.xml')/root/element"/>

Nov 18, 2014 at 10:38 PM
Did you try using the -EnableDTD or-EnableScript parameters on Convert-Xml?
Nov 19, 2014 at 3:50 PM
I had tried -EnableScript and it didn't help. Wasn't aware of -EnableDTD but that doesn't change it either. Apparently document() is disallowed by default with an XslCompiledTransform. Are there any other switches/parameters for Convert-Xml ?
Apr 1, 2015 at 9:07 PM
In case anybody else encounters this problem, I ended up using this code to allow the document() in a variable. Not pscx (but it could be in future?)
$xsl = New-Object System.Xml.Xsl.XslCompiledTransform
$resolver = New-Object System.Xml.XmlUrlResolver
$xslSettings = New-Object System.Xml.Xsl.XsltSettings($false,$true)
$xslSettings.EnableDocumentFunction = $true
$xsl.Load($xslt, $xslSettings, $resolver)
$xsl.Transform($File, $OutFile)