XmlTransformationAlias.

XmlTransform(ICakeContext, string, string) Method

Summary

Performs XML XSL transformation.
Namespace
Cake.Common.Xml
Containing Type
XmlTransformationAlias

Syntax

[CakeMethodAlias]
public static string XmlTransform(this ICakeContext context, string xsl, string xml)

Examples

This example code will convert xml to a new xml structure using XmlTransform alias.
 string xsl = @"<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
   <xsl:output method=""xml"" omit-xml-declaration=""yes"" />
   <xsl:template match=""/"">
     <xsl:for-each select=""pastery/cake"" >
         <price><xsl:value-of select=""@price""/></price>
       </xsl:for-each>
   </xsl:template>
 </xsl:stylesheet>";

 string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
 <pastery>
     <cake price=""1.62"" />
 </pastery>";

 var priceTag = XmlTransform(xsl, xml);

Result:

<price>1.62</price>

Attributes

Type Description
CakeMethodAliasAttribute An attribute used to mark script method aliases.

Parameters

Name Type Description
context ICakeContext The context.
xsl string XML style sheet.
xml string XML data.

Return Value

Type Description
string Transformed XML string.