Skip to content

Commit

Permalink
Better class inheritance, cleaned debug junk
Browse files Browse the repository at this point in the history
  • Loading branch information
ottoville committed Feb 5, 2016
1 parent d943a94 commit 07f9939
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 66 deletions.
34 changes: 15 additions & 19 deletions docx2html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<xsl:value-of select="$cssrules"/>
</xsl:attribute>
<style>
<xsl:attribute name="scoped"/>
<!--<xsl:attribute name="scoped"/>-->
<xsl:choose>
<xsl:when test="local-name(.)='sdtPr'">
<xsl:value-of select="$scopeselector"/> { <xsl:apply-templates select="w:rPr" /> }
Expand All @@ -201,6 +201,14 @@

<meta name="{'generator'}" content="{'docx2html.xsl https://github.com/ottoville/DOCX2HTML.XSLT'}"/>
<article>
<!-- Match always last paragraph of page -->
<xsl:for-each select="*[w:pPr/w:sectPr or (w:r/w:br/@w:type='page' and not(./following-sibling::*[1][w:pPr/w:sectPr]))]|w:sectPr">
<xsl:call-template name="sections">
<xsl:with-param name="reldocument" select="resolve-uri('_rels/document.xml.rels',base-uri())" />
<xsl:with-param name="themefile" select="$themefile" />
</xsl:call-template>
</xsl:for-each>
</article>
<style>
ins {text-decoration:none;}
ul {list-style-position:inside}
Expand All @@ -210,16 +218,12 @@
ul, li { margin:0;padding:0 } li p {} input[type="text"] {height:18px} input[type="checkbox"] { margin:0 } p {margin:0;position:relative}
article>* {display:none} article>section {display:block; margin-top:0.1cm;border-width:1px;border-style:solid;position:relative;}
<xsl:value-of select="base-uri(.)"/>
<xsl:for-each select="document(resolve-uri('styles.xml',base-uri()))/w:styles/w:style">
<xsl:choose>
<xsl:when test="@w:type='paragraph'">
p.<xsl:value-of select="./@w:styleId"/> { <xsl:apply-templates select="w:pPr" /> }
p.<xsl:value-of select="./@w:styleId"/> span { <xsl:apply-templates select="w:rPr" /> }
</xsl:when>
<xsl:when test="@w:type='character'">
span.<xsl:value-of select="./@w:styleId"/> { <xsl:apply-templates select="w:rPr" /> }
</xsl:when>
</xsl:choose>
<xsl:for-each select="document(resolve-uri('styles.xml',base-uri()))/w:styles/w:style[@w:type='paragraph']">
<xsl:value-of select="concat('p.',./@w:styleId,' { ')"/><xsl:apply-templates select="w:pPr" /> }
<xsl:value-of select="concat('p.',./@w:styleId,'>span { ')"/><xsl:apply-templates select="w:rPr" /> }
</xsl:for-each>
<xsl:for-each select="document(resolve-uri('styles.xml',base-uri()))/w:styles/w:style[@w:type='character']">
<xsl:value-of select="concat('span.',./@w:styleId,' { ')"/><xsl:apply-templates select="w:rPr" /> }
</xsl:for-each>
<xsl:for-each select="document(resolve-uri('numbering.xml',base-uri()))/w:numbering/w:num">
<xsl:variable name="listid" select="@w:numId"/>
Expand Down Expand Up @@ -263,14 +267,6 @@
}
</xsl:for-each>
</style>
<!-- Match always last paragraph of page -->
<xsl:for-each select="*[w:pPr/w:sectPr or (w:r/w:br/@w:type='page' and not(./following-sibling::*[1][w:pPr/w:sectPr]))]|w:sectPr">
<xsl:call-template name="sections">
<xsl:with-param name="reldocument" select="resolve-uri('_rels/document.xml.rels',base-uri())" />
<xsl:with-param name="themefile" select="$themefile" />
</xsl:call-template>
</xsl:for-each>
</article>
<script>
<xsl:text>
<![CDATA[
Expand Down
7 changes: 5 additions & 2 deletions images.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,15 @@
<xsl:with-param name="themefile" select="$themefile" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="v:roundrect|v:shape">
<xsl:template match="v:roundrect|v:shape|v:group">
<xsl:param name="reldocument" />
<xsl:param name="themefile" />
<div>
<xsl:attribute name="style">
<xsl:value-of select="@style"/>
<xsl:value-of select="@style"/>;
<xsl:if test="@fillcolor">
<xsl:value-of select="concat('background-color:',@fillcolor,';')"/>;
</xsl:if>
</xsl:attribute>
<xsl:apply-templates select="v:textbox">
<xsl:with-param name="reldocument" select="$reldocument" />
Expand Down
3 changes: 2 additions & 1 deletion paragraphs.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<xsl:if test="local-name(..)='sdtContent'">
<xsl:value-of select="concat(' ',generate-id(../..))"/>
</xsl:if>
<xsl:value-of select="concat(' ',$currentid)"/>
</xsl:variable>
<xsl:apply-templates select="w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor[wp:positionH/@relativeFrom='page' or wp:positionV/@relativeFrom='page']">
<xsl:with-param name="listintend" select="$listintend" />
Expand All @@ -78,7 +79,7 @@
</xsl:apply-templates>
<p class="{normalize-space($class)}" pid="{$currentid}">
<xsl:apply-templates select="w:pPr|w:r[(w:tab or not(./following-sibling::w:r[w:tab]))]|w:ins|w:hyperlink|w:sdt">
<xsl:with-param name="scopeselector">p[pid='<xsl:value-of select="$currentid"/>']</xsl:with-param>
<xsl:with-param name="scopeselector">.<xsl:value-of select="$currentid"/></xsl:with-param>
<xsl:with-param name="listintend" select="$listintend" />
<xsl:with-param name="reldocument" select="$reldocument" />
<xsl:with-param name="themefile" select="$themefile" />
Expand Down
53 changes: 14 additions & 39 deletions table.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,26 @@
version="2.0">
<xsl:template match="w:tc">
<xsl:param name="reldocument" />
<xsl:if test="count(w:tcPr/w:vMerge[not(@w:val='restart')])=0">
<td>
<xsl:if test="count(w:tcPr/w:vMerge[@w:val='restart'])">
<xsl:variable name="rowposition" select="count(../preceding-sibling::w:tr) + 1" />
<xsl:variable name="curpos" select="position()" />
<xsl:variable name="nextrestart">
<xsl:choose>
<xsl:when test="count(../following-sibling::w:tr/w:tc/w:tcPr/w:vMerge[@w:val='restart']/../../../preceding-sibling::w:tr)">
<xsl:value-of select="count(../following-sibling::w:tr/w:tc/w:tcPr/w:vMerge[@w:val='restart']/../../../preceding-sibling::w:tr)+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'no'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$nextrestart='no'">
<xsl:attribute name="rowspan">
<xsl:value-of select="count(../following-sibling::w:tr/w:tc/w:tcPr/w:vMerge)+1"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="../following-sibling::w:tr[position() &lt; $nextrestart]/*[position()=$curpos]/w:tcPr/w:vMerge">
<xsl:variable name="thisrowposition" select="count(./preceding-sibling::w:tr) + 1 - $rowposition" />

<xsl:value-of select="$thisrowposition"/>|
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="count(w:tcPr/w:gridSpan)">
<xsl:attribute name="colspan"><xsl:value-of select="w:tcPr/w:gridSpan/@w:val"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="w:tcPr|w:p|w:sdt">
<xsl:with-param name="reldocument" select="$reldocument" />
</xsl:apply-templates>
</td>
</xsl:if>
<td>
<xsl:if test="w:tcPr/w:vMerge[@w:val='restart']">
<xsl:attribute name="rowspan">
<xsl:value-of select="count(../following-sibling::w:tr/w:tc/w:tcPr/w:vMerge)+1"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="w:tcPr/w:gridSpan">
<xsl:attribute name="colspan"><xsl:value-of select="w:tcPr/w:gridSpan/@w:val"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="w:tcPr|w:p|w:sdt">
<xsl:with-param name="reldocument" select="$reldocument" />
</xsl:apply-templates>
</td>
</xsl:template>
<xsl:template match="w:tr">
<xsl:param name="reldocument" />
<xsl:param name="trscopeselector">tr[data-rid="<xsl:value-of select="generate-id(.)"/>"]</xsl:param>
<tr>
<xsl:attribute name="data-rid" select="generate-id(.)"/>
<xsl:apply-templates select="w:trPr|w:tc|w:sdt">
<xsl:apply-templates select="w:trPr|w:tc[not(w:tcPr/w:vMerge[not(@w:val='restart')])]|w:sdt">
<xsl:with-param name="scopeselector" select="$trscopeselector" />
<xsl:with-param name="reldocument" select="$reldocument" />
</xsl:apply-templates>
Expand Down
10 changes: 5 additions & 5 deletions text.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
<xsl:when test='local-name(.)="kern" and number(../w:sz/@w:val) &gt;= number(@w:val)'>
font-kerning:auto;
</xsl:when>
<xsl:when test="local-name(.)='shd'">background-color:#<xsl:value-of select="@w:fill"/>;</xsl:when>
<xsl:when test="local-name(.)='rFonts'">font-family:<xsl:value-of select="@w:*[1]"/>;</xsl:when>
<xsl:when test="local-name(.)='color'">color:#<xsl:value-of select="@w:val"/>;</xsl:when>
<xsl:when test="local-name(.)='shd'"><xsl:value-of select="concat('background-color:#',@w:fill,';')"/></xsl:when>
<xsl:when test="local-name(.)='rFonts'"><xsl:value-of select="concat('font-family:',@w:*[1],';')"/></xsl:when>
<xsl:when test="local-name(.)='color'"><xsl:value-of select="concat('color:#',@w:val,';')"/></xsl:when>
<xsl:when test="local-name(.)='sz' or local-name(.)='szCs'">
<xsl:choose>
<xsl:when test='number(@w:val) &gt; 0'>
font-size:<xsl:value-of select='number(@w:val) div 2'/>pt;
<xsl:value-of select="concat('font-size:',number(@w:val) div 2,'pt;')"/>
</xsl:when>
<xsl:otherwise>
font-size:<xsl:value-of select="0"/>;
font-size:0;
</xsl:otherwise>
</xsl:choose>
</xsl:when>
Expand Down

0 comments on commit 07f9939

Please sign in to comment.