XSLT processor with PowerShell
Here is a simple way to transform XML document with specified XSL in PowerShell. It is easy achieavable using the System.Xml.Xsl namespace of the .NET.
PARAM
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$XmlPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$XslPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$HtmlOutput
)
try
{
$XslPatht = New-Object System.Xml.Xsl.XslCompiledTransform
$XslPatht.Load($XslPath)
$XslPatht.Transform($XmlPath, $HtmlOutput)
Write-Host "Generated output is on path: $HtmlOutput"
}
catch
{
Write-Host $_.Exception -ForegroundColor Red
}
We pass the path to the XML file and the path to the XSL file. Also the path where we want to save the transformed HTML file.
All validations for the parameters if they are null or empty are done by the PowerShell itself. For the moment there is no validation
if the paths are valid and if the files exists. It is ok because the script anyway will not complete as expected with the check or without it.