source: trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/html2wordml.xslt @ 374

Revision 374, 2.1 KB checked in by jharrop, 4 years ago (diff)

Very basic working implementation of code to convert html to WordML

Line 
1<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2        xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3        xmlns:o="urn:schemas-microsoft-com:office:office"
4        xmlns:v="urn:schemas-microsoft-com:vml"
5        xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6        xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7        xmlns:w10="urn:schemas-microsoft-com:office:word"
8        xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"         
9        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10        xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11        xmlns:java="http://xml.apache.org/xalan/java"
12        version="1.0"
13        exclude-result-prefixes="java msxsl ext w o v WX aml w10">     
14
15       
16<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
17        <!-- doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" -->
18
19<!--
20
21<p class="Normal-P"> <span class="Normal-H">blagh blagh</span></p>
22<p class="Normal-P">&nbsp; blagh blagh <br /></p> 
23
24should become
25
26<w:p>
27        <w:r>
28            <w:t></w:t>
29        </w:r>
30</w:p>
31
32
33 -->
34
35<xsl:template match="/ | html">
36       
37                <xsl:apply-templates select="//body" />
38
39</xsl:template>
40
41
42<xsl:template match="body">
43       
44        <w:sdtContent>
45                <xsl:apply-templates/>
46        </w:sdtContent>
47
48</xsl:template>
49
50<xsl:template match="br"/> <!-- ignore for now -->
51
52<xsl:template match="p">
53        <w:p>
54                <xsl:apply-templates select="node()|@*"/>       
55        </w:p>
56</xsl:template>
57
58<xsl:template match="span">
59        <w:r>
60                <w:t>
61                        <xsl:apply-templates/> 
62                </w:t>
63        </w:r>
64</xsl:template>
65
66<xsl:template match="text()">
67        <xsl:choose>
68                <xsl:when test="name(..)='span'">
69                        <xsl:value-of select="."/>
70                </xsl:when>
71                <xsl:when test="name(..)='p'">
72                        <w:r>
73                                <w:t>
74                                        <xsl:value-of select="."/>
75                                </w:t>
76                        </w:r>
77                </xsl:when>
78                <xsl:otherwise>
79                        <xsl:comment>What to do with text '<xsl:value-of select="."/>' in <xsl:value-of select="name(..)"/> element?</xsl:comment>
80                </xsl:otherwise>
81        </xsl:choose>
82</xsl:template>
83
84
85<xsl:template match="@class[string(.)='Normal-P']">
86        <!--  this is the default, so it can be ignored -->
87</xsl:template>
88
89
90
91</xsl:stylesheet>
92
Note: See TracBrowser for help on using the repository browser.