source: trunk/docx4j/src/main/java/org/docx4j/jaxb/mc-preprocessor.xslt @ 1605

Revision 1605, 2.8 KB checked in by jharrop, 11 months ago (diff)

Proof of concept of an mc:AlternateContent preprocessor.

Line 
1
2<xsl:stylesheet 
3
4        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5       
6        xmlns:java="http://xml.apache.org/xalan/java" 
7       
8        xmlns:o="urn:schemas-microsoft-com:office:office"
9        xmlns:v="urn:schemas-microsoft-com:vml"
10        xmlns:w10="urn:schemas-microsoft-com:office:word"
11       
12        xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
13       
14        xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
15       
16        xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
17        xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" 
18        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
19        xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
20        xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"             
21        xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
22        xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
23        xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" 
24        xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
25       
26        xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
27        xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" 
28        xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" 
29        xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" 
30        xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" 
31        xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
32               
33    version="1.0"
34        exclude-result-prefixes="java w a o v WX aml w10 pkg wp pic">   
35       
36<!--  This is a mc:AlternateContent pre-processor.
37      It selects the mc:Fallback content, which
38      docx4j 2.7.0 ought to be able to handle. 
39     
40      See MainDocumentPart's unmarshall method
41      for an example of how it is invoked. -->
42
43
44<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
45
46  <xsl:template match="/ | @*|node()">
47    <xsl:copy>
48      <xsl:apply-templates select="@*|node()"/>
49    </xsl:copy>
50  </xsl:template>
51
52  <xsl:template match="mc:AlternateContent"> 
53 
54        <xsl:variable name="dummy" 
55                select="java:org.docx4j.utils.XSLTUtils.logWarn('Found some mc:AlternateContent')" />
56               
57        <xsl:choose>
58                <xsl:when test="mc:Fallback">
59               
60                        <xsl:variable name="message" 
61                                select="concat('Selecting ', name(mc:Fallback/*[1]) )" />                       
62                        <xsl:variable name="logging" 
63                                select="java:org.docx4j.utils.XSLTUtils.logWarn($message)" />
64                               
65                        <xsl:copy-of select="mc:Fallback/*"/>
66                       
67                </xsl:when>
68                <xsl:otherwise> 
69                        <xsl:variable name="logging" 
70                                select="java:org.docx4j.utils.XSLTUtils.logWarn('Missing mc:Fallback!  What to do?')" />
71                        <!--  Hope for the best.. -->
72                        <xsl:copy-of select="mc:Choice[1]/*"/>
73                </xsl:otherwise>               
74        </xsl:choose>   
75  </xsl:template>
76
77   
78</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.