Witam
Do transformacji html znalazłem kod
XslTransform xslt = new XslTransform();
xslt.Load(sXslPath);
XPathDocument xpath = new XPathDocument(sXmlPath);
XmlTextWriter xwriter = new XmlTextWriter(sXmlPath + ".html", Encoding.UTF8);
xslt.Transform(xpath, null, xwriter, null);
xwriter.Close();
a do rtf
DataSet ds;
XmlDataDocument xmlDoc;
XslCompiledTransform xslTran;
XmlElement root;
XPathNavigator nav;
XmlTextWriter writer;
ds = new DataSet();
ds.ReadXml(xml);
xmlDoc = new XmlDataDocument(ds);
xslTran = new XslCompiledTransform();
xslTran.Load(xsl);
root = xmlDoc.DocumentElement;
nav = root.CreateNavigator();
writer = new XmlTextWriter(xml+".rtf", System.Text.Encoding.Default);
xslTran.Transform(nav, writer);
writer.Close();
przykładowy xml
<?xml version="1.0" encoding="utf-8" ?>
<Employee>
<Record>
<EmpID>E1</EmpID>
<EmpName>Sudipta</EmpName>
<EmpAge>29</EmpAge>
<EmpSex>M</EmpSex>
<EmpAddress>Kolkata</EmpAddress>
<Department>
<DeptID>D1</DeptID>
<EmpID>E1</EmpID>
<DeptName>Sales</DeptName>
</Department>
</Record>
</Employee>
i xsl
<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="prosta-strona"
page-height="10cm" page-width="10cm"
margin-top="1cm" margin-bottom="1cm"
margin-left="1cm" margin-right="1cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="prosta-strona">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="center" text-decoration="underline" space-after="1cm">
<xsl:text>Przykład XSL-FO</xsl:text>
</fo:block>
<fo:block>
<xsl:text>To jest banalny przykład XSL-FO.</xsl:text>
</fo:block>
<fo:block>
<xsl:apply-templates />
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="Employee">
<!--Print Employee Records-->
<xsl:text>Przykład XSL-FO</xsl:text>
<xsl:apply-templates select="Record" />
</xsl:template>
<xsl:template match="Record">
<fo:block text-align="center" text-decoration="underline" space-after="1cm">
<xsl:value-of select="EmpName" />
</fo:block>
<xsl:value-of select="EmpAge" />
<xsl:if test="EmpSex='M'">
<xsl:text>Male</xsl:text>
</xsl:if>
<xsl:if test="EmpSex='F'">
<xsl:text>Female</xsl:text>
</xsl:if>
<xsl:value-of select="EmpAddress" />
<!--Print Employee Department-->
<xsl:apply-templates select="Department" />
</xsl:template>
<xsl:template match="Department">
<xsl:value-of select="DeptName" />
</xsl:template>
</xsl:stylesheet>
kod do transformacji html nie generuje htmla tylko xmla, a kod do rtf tworzy plik tekstowy. Transformacja Rtf nie wstawia zawartości która jest poza <xsl:template ... czyli 'Przykład XSL-FO' nie jest wstawiony do pliku wynikowega, ale w transformacji html jest.
Co ciekawe podobne przykłady są podawane na stronach microsoftu np. https://msdn.microsoft.com/en-us/library/aa537151%28v=office.11%29.aspx.
Jeden z przykładów jaki znalazłem zdumiał mnie bo wynika z niego że aby uzyskać htmla to w xsl muszę jawnie stosować jako tekst elementy htmlowe, a w rtfie formatowanie z tego typu.
No przecież jakbym chciał ręcznie każdy typ przygotowywać to po co mi transformacja.
Jak to jest z tą transformacją z xsl.
Czy ktoś może zaproponować jakieś darmowe sprawdzone na .NET4.0 biblioteki do Pdf, doc, docx. Kilka znalazłem ale niestety nic z tego nie wyszło. Czy jest na .NET40 http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en bo nie znalazłem, a nie chcę specjalnie instalować też .NET20