Skip to content

Instantly share code, notes, and snippets.

@djfr
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djfr/cb9baaa000dc8f6ce4b1 to your computer and use it in GitHub Desktop.
Save djfr/cb9baaa000dc8f6ce4b1 to your computer and use it in GitHub Desktop.
param
(
[parameter(Mandatory=$true)]
[string]
$Xml,
[parameter(Mandatory=$true)]
[string]
$Xdt
)
if (!(Test-Path -path $Xml -PathType Leaf))
{
throw "XML File not found. $Xml"
}
if (!(Test-Path -path $Xdt -PathType Leaf))
{
throw "XDT File not found. $Xdt"
}
Add-Type -LiteralPath "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\spzpqgng.yjx\Microsoft.Web.XmlTransform.dll"
$xmldoc = New-Object Microsoft.Web.XmlTransform.XmlTransformableDocument
$xmldoc.PreserveWhitespace = $true
$xmldoc.Load($Xml)
$transf = New-Object Microsoft.Web.XmlTransform.XmlTransformation($xdt)
if ($transf.Apply($xmldoc) -eq $false)
{
throw "Transformation failed."
}
$xmldoc.Save("$PSScriptRoot\out.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment