본문 바로가기

CSharp/Development

Xml Xslt Transform with C#

C#

/// <summary>
/// Xml, Xslt를 Transform 한 Data를 Return 한다.
/// </summary>
/// <param name="doc">Xml 문서</param>
/// <param name="xsltPath">Xslt 절대경로</param>
/// <returns>Transoform string Data</returns>
#region // string XmlTranseform(XmlDocument doc, string xsltPath) //
public string XmlTranseform(XmlDocument doc, string xsltPath)
{
	XslCompiledTransform xtData = new XslCompiledTransform();
	xtData.Load(xsltPath);

	StringWriter swData = new StringWriter();
	xtData.Transform(doc, null, swData);

	return swData.ToString();
}
#endregion

/// <summary>
/// Xml, Xslt를 Transform 한 Data를 Return 한다.
/// </summary>
/// <param name="strXml">Xml String Data</param>
/// <param name="xsltPath">Xslt 절대경로</param>
/// <returns>Transoform string Data</returns>
#region // string XmlTranseform(string strXml, string xsltPath) //
public string XmlTranseform(string strXml, string xsltPath)
{
	XmlDocument doc = new XmlDocument();
	doc.LoadXml(strXml);

	XslCompiledTransform xtData = new XslCompiledTransform();
	xtData.Load(xsltPath);

	StringWriter swData = new StringWriter();
	xtData.Transform(doc, null, swData);

	return swData.ToString();
}
#endregion