2016-10-15 02:58:13 +08:00
<?xml version="1.0"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:o= "urn:schemas-microsoft-com:office:office" xmlns:r= "http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v= "urn:schemas-microsoft-com:vml" xmlns:w= "http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10= "urn:schemas-microsoft-com:office:word" xmlns:wp= "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wps= "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg= "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wp14= "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:w14= "http://schemas.microsoft.com/office/word/2010/wordml" >
2016-10-15 03:43:23 +08:00
<xsl:output method= "text" />
2016-10-15 02:58:13 +08:00
<xsl:template match= "/" >
<xsl:apply-templates select= "/w:document/w:body/*" />
</xsl:template>
2016-10-15 03:43:23 +08:00
<!-- Ignore these -->
<xsl:template match= "w:p[starts-with(w:pPr/w:pStyle/@w:val, 'TOC')]" />
2016-11-01 01:51:27 +08:00
<xsl:template match= "w:p[starts-with(w:pPr/w:pStyle/@w:val, 'Contents1')]" />
<xsl:template match= "w:p[starts-with(w:pPr/w:pStyle/@w:val, 'Contents2')]" />
<xsl:template match= "w:p[starts-with(w:pPr/w:pStyle/@w:val, 'Contents3')]" />
2016-10-15 03:43:23 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'ChapterStart']" />
2016-11-01 01:51:27 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'Normal']" />
2016-11-30 23:12:22 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'Standard']" />
2016-10-15 03:43:23 +08:00
2016-10-15 04:31:55 +08:00
<!-- Paragraph styles -->
2016-10-15 03:43:23 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'ChapterTitle']" >
2016-10-15 04:29:12 +08:00
<xsl:text > [TOC] </xsl:text>
2016-10-15 03:43:23 +08:00
<xsl:text > # </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 03:43:23 +08:00
<xsl:text > </xsl:text>
</xsl:template>
2016-10-15 03:49:29 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'HeadA']" >
<xsl:text > ## </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 05:20:52 +08:00
<xsl:text > </xsl:text>
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'HeadB']" >
<xsl:text > ### </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 05:20:52 +08:00
<xsl:text > </xsl:text>
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'HeadC']" >
<xsl:text > #### </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 03:49:29 +08:00
<xsl:text > </xsl:text>
</xsl:template>
2016-11-01 01:51:27 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'HeadBox']" >
<xsl:text > ### </xsl:text>
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:template>
2016-10-15 07:56:52 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'NumListA' or @w:val = 'NumListB']]" >
<xsl:text > 1. </xsl:text>
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'NumListC']]" >
<xsl:text > 1. </xsl:text>
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:template>
2016-11-01 01:51:27 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'BulletA' or @w:val = 'BulletB']]" >
<xsl:text > * </xsl:text>
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'BulletC']]" >
<xsl:text > * </xsl:text>
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:template>
2016-11-30 23:12:22 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'BodyFirst' or @w:val = 'Body' or @w:val = 'BodyFirstBox' or @w:val = 'BodyBox' or @w:val = '1stPara']]" >
2016-10-15 09:32:20 +08:00
<xsl:if test= ".//w:t" >
<xsl:apply-templates select= "*" />
<xsl:text > </xsl:text>
</xsl:if>
2016-10-15 03:43:23 +08:00
</xsl:template>
2016-10-15 03:49:29 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'CodeA']" >
<xsl:text > ``` </xsl:text>
2016-10-15 07:41:42 +08:00
<!-- Don't apply Emphasis/etc templates in code blocks -->
<xsl:for-each select= "w:r" >
<xsl:value-of select= "w:t" />
</xsl:for-each>
2016-10-15 03:49:29 +08:00
<xsl:text > </xsl:text>
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'CodeB']" >
2016-10-15 07:41:42 +08:00
<!-- Don't apply Emphasis/etc templates in code blocks -->
<xsl:for-each select= "w:r" >
<xsl:value-of select= "w:t" />
</xsl:for-each>
2016-10-15 04:55:59 +08:00
<xsl:text > </xsl:text>
2016-10-15 03:49:29 +08:00
</xsl:template>
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'CodeC']" >
2016-10-15 07:41:42 +08:00
<!-- Don't apply Emphasis/etc templates in code blocks -->
<xsl:for-each select= "w:r" >
<xsl:value-of select= "w:t" />
</xsl:for-each>
2016-10-15 03:49:29 +08:00
<xsl:text > ``` </xsl:text>
</xsl:template>
2016-10-15 05:15:24 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'CodeSingle']" >
<xsl:text > ``` </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 05:15:24 +08:00
<xsl:text > ``` </xsl:text>
</xsl:template>
2016-10-15 04:53:20 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'ProductionDirective']" >
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 04:53:20 +08:00
<xsl:text > </xsl:text>
</xsl:template>
2016-11-01 01:51:27 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle[@w:val = 'Caption' or @w:val = 'TableTitle' or @w:val = 'Caption1']]" >
2016-10-15 04:59:33 +08:00
<xsl:text > < caption> </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 04:59:33 +08:00
<xsl:text > < /caption></xsl:text>
<xsl:text > </xsl:text>
</xsl:template>
2016-10-15 05:53:17 +08:00
<xsl:template match= "w:p[w:pPr/w:pStyle/@w:val = 'Note']" >
<xsl:text > > </xsl:text>
2016-10-15 07:41:13 +08:00
<xsl:apply-templates select= "*" />
2016-10-15 05:53:17 +08:00
<xsl:text > </xsl:text>
</xsl:template>
2016-10-15 02:58:13 +08:00
<xsl:template match= "w:p" >
2016-10-15 03:43:23 +08:00
Unmatched: <xsl:value-of select= "w:pPr/w:pStyle/@w:val" />
<xsl:text >
</xsl:text>
2016-10-15 02:58:13 +08:00
</xsl:template>
2016-10-15 04:31:55 +08:00
<!-- Character styles -->
2016-11-30 23:12:22 +08:00
<xsl:template match= "w:r[w:rPr/w:rStyle[@w:val = 'Literal' or @w:val = 'LiteralBold' or @w:val = 'EmphasisBold' or @w:val = 'LiteralCaption']]" >
2016-10-15 05:49:04 +08:00
<xsl:choose >
<xsl:when test= "normalize-space(w:t) != ''" >
2016-10-15 09:36:57 +08:00
<xsl:if test= "starts-with(w:t, ' ')" >
<xsl:text > </xsl:text>
</xsl:if>
2016-10-15 05:49:04 +08:00
<xsl:text > `</xsl:text>
<xsl:value-of select= "normalize-space(w:t)" />
<xsl:text > `</xsl:text>
<xsl:if test= "substring(w:t, string-length(w:t)) = ' '" >
<xsl:text > </xsl:text>
</xsl:if>
</xsl:when>
2016-10-15 09:29:05 +08:00
<xsl:when test= "normalize-space(w:t) != w:t and w:t != ''" >
2016-10-15 05:49:04 +08:00
<xsl:text > </xsl:text>
</xsl:when>
</xsl:choose>
2016-10-15 04:31:55 +08:00
</xsl:template>
2016-11-30 23:12:22 +08:00
<xsl:template match= "w:r[w:rPr/w:rStyle[@w:val = 'EmphasisItalic' or @w:val = 'EmphasisItalicBox' or @w:val = 'EmphasisNote']]" >
2016-10-15 04:31:55 +08:00
<xsl:choose >
<xsl:when test= "normalize-space(w:t) != ''" >
2016-10-15 09:36:57 +08:00
<xsl:if test= "starts-with(w:t, ' ')" >
<xsl:text > </xsl:text>
</xsl:if>
2016-10-15 04:31:55 +08:00
<xsl:text > *</xsl:text>
2016-10-15 04:53:37 +08:00
<xsl:value-of select= "normalize-space(w:t)" />
2016-10-15 04:31:55 +08:00
<xsl:text > *</xsl:text>
2016-10-15 04:53:37 +08:00
<xsl:if test= "substring(w:t, string-length(w:t)) = ' '" >
<xsl:text > </xsl:text>
</xsl:if>
2016-10-15 04:31:55 +08:00
</xsl:when>
<xsl:otherwise >
2016-10-15 04:53:37 +08:00
<xsl:text > </xsl:text>
2016-10-15 04:31:55 +08:00
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match= "w:r" >
<xsl:value-of select= "w:t" />
</xsl:template>
2016-10-15 02:58:13 +08:00
</xsl:stylesheet>