Create a gist now

Instantly share code, notes, and snippets.

@subTee /calc.xslt Secret
Last active Feb 15, 2017

Execute C# From XSLT - Just Interesting
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="urn:MyModule">
<msxsl:script implements-prefix="my" language="C#">
public void Exec()
{
System.Diagnostics.Process.Start("Calc.exe");
}
</msxsl:script>
<xsl:template match="data">
<result>
<xsl:value-of select="my:Exec()" />
</result>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?><data></data>
$path = "C:\Tools\Research"
$xslt_settings = new-object System.XML.XSl.XsltSettings
$xslt_settings.EnableScript = $true
$xslt = new-object System.XML.Xsl.XslCompiledTransform
$XmlResolver = new-object System.XML.XmlUrlResolver
$xslt.Load("$Path\calc.xslt",$xslt_settings, $XmlResolver)
$doc = new-object -Type System.Xml.XPath.XPathDocument -ArgumentList "$Path\example.xml"
$settings = new-object System.XML.XMLWriterSettings
$settings.OmitXmlDeclaration = $true
$settings.Indent = $true
$writer = [System.XML.XmlWriter]::Create("$Path\output.xml", $settings)
$xslt.Transform($doc,$writer)
$writer.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment