Skip to content

Instantly share code, notes, and snippets.

@leoloobeek
Created March 8, 2018 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leoloobeek/708aa399403ac5957a69fa1a2adfbdbb to your computer and use it in GitHub Desktop.
Save leoloobeek/708aa399403ac5957a69fa1a2adfbdbb to your computer and use it in GitHub Desktop.
XSLT C# Examples
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts">
<msxsl:script language="C#" implements-prefix="user">
<![CDATA[
public double circumference(double radius){
double pi = 3.14;
double circ = pi*radius*2;
Console.WriteLine("Hey There");
return circ;
}
]]>
</msxsl:script>
<xsl:template match="data">
<circles>
<xsl:for-each select="circle">
<circle>
<xsl:copy-of select="node()"/>
<circumference>
<xsl:value-of select="user:circumference(radius)"/>
</circumference>
</circle>
</xsl:for-each>
</circles>
</xsl:template>
</xsl:stylesheet>
<?xml version='1.0'?>
<data>
<circle>
<radius>12</radius>
</circle>
<circle>
<radius>37.5</radius>
</circle>
</data>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="Example">
<ItemGroup>
<XmlFiles Include="https://gist.githubusercontent.com/caseysmithrc/8e58d11bc99e496a19424fbe5a99175f/raw/eac5a3114138e54f628489dbd50fb08fac5f2a32/Numbers.Xml" />
</ItemGroup>
<PropertyGroup>
<XslFile>https://gist.githubusercontent.com/caseysmithrc/8e58d11bc99e496a19424fbe5a99175f/raw/eac5a3114138e54f628489dbd50fb08fac5f2a32/calc.xsl</XslFile>
</PropertyGroup>
<XslTransformation
OutputPaths="blah"
XmlInputPaths="%(XmlFiles.Identity)"
XslInputPath="$(XslFile)"
/>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment