Skip to content

Commit

Permalink
Clean plugin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jelovirt committed May 30, 2017
1 parent 7000c5e commit b590295
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 52 deletions.
49 changes: 48 additions & 1 deletion docx/word/comments.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

<xsl:template match="/">
<w:comments mc:Ignorable="w14 wp14">
<xsl:apply-templates select="//*[contains(@class, ' topic/draft-comment ')]"/>
<xsl:apply-templates select="//*[contains(@class, ' topic/draft-comment ')] |
//processing-instruction('oxy_comment_start')"/>
</w:comments>
</xsl:template>

Expand Down Expand Up @@ -61,4 +62,50 @@
</w:comment>
</xsl:template>

<xsl:template match="processing-instruction('oxy_comment_start')">
<xsl:variable name="attributes" as="element()">
<res>
<xsl:apply-templates select="." mode="x:parse-pi"/>
</res>
</xsl:variable>
<w:comment w:id="{$attributes/@draft-comment-number}">
<xsl:if test="$attributes/@author">
<xsl:attribute name="w:author" select="$attributes/@author"/>
<xsl:attribute name="w:initials">
<xsl:for-each select="tokenize($attributes/@author, '\s+')">
<xsl:value-of select="upper-case(substring(., 1, 1))"/>
</xsl:for-each>
</xsl:attribute>
</xsl:if>
<xsl:if test="$attributes/@timestamp">
<xsl:attribute name="w:date" select="replace($attributes/@timestamp, '(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})([-+]\d{4}|Z)', '$1-$2-$3T$4:$5:$6$7')"/>
</xsl:if>
<w:p>
<w:pPr>
<w:pStyle w:val="CommentText"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="CommentReference"/>
</w:rPr>
<w:annotationRef/>
</w:r>
<w:r>
<xsl:for-each select="tokenize($attributes/@comment, '&#xA;')">
<xsl:if test="position() ne 1">
<w:br/>
</xsl:if>
<w:t>
<xsl:variable name="apos" as="xs:string">'</xsl:variable>
<xsl:variable name="quot" as="xs:string">"</xsl:variable>
<xsl:value-of select="replace(replace(.,
'&amp;apos;', $apos),
'&amp;quot;', $quot)"/>
</w:t>
</xsl:for-each>
</w:r>
</w:p>
</w:comment>
</xsl:template>

</xsl:stylesheet>
9 changes: 8 additions & 1 deletion docx/word/document.abbrev-d.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<xsl:variable name="first-use-scope-root" as="element()">
<xsl:call-template name="get-first-use-scope-root"/>
</xsl:variable>
<xsl:sequence select="not(generate-id(.) = generate-id(key('abbreviated-form-keyref', @keyref, $first-use-scope-root)[1]))"/>
<xsl:sequence select="not(x:generate-id(.) = x:generate-id(key('abbreviated-form-keyref', @keyref, $first-use-scope-root)[1]))"/>
</xsl:template>
<xsl:template match="*[contains(@class,' topic/copyright ')]//*" mode="use-abbreviated-form" as="xs:boolean">
<xsl:sequence select="false()"/>
Expand Down Expand Up @@ -116,6 +116,13 @@
</xsl:choose>
</xsl:template>

<xsl:template match="*" mode="getMatchingDefinition">
<xsl:variable name="def" select="*[contains(@class, ' glossentry/glossdef ')]"/>
<xsl:if test="exists($def)">
<xsl:apply-templates select="$def/node()"/>
</xsl:if>
</xsl:template>

<xsl:template match="*" mode="ditamsg:no-glossentry-for-abbreviated-form">
<xsl:param name="keys"/>
<xsl:call-template name="output-message">
Expand Down
85 changes: 48 additions & 37 deletions docx/word/document.flat.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@
<xsl:import href="document.utils.xsl"/>
<xsl:import href="flatten.xsl"/>

<xsl:variable name="content" as="document-node()">
<xsl:document>
<xsl:apply-templates select="node()" mode="flatten"/>
</xsl:document>
</xsl:variable>
<xsl:variable name="lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/ol ') or contains(@class, ' topic/ul ') or contains(@class, ' topic/sl ')]">
<xsl:value-of select="generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="image-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/image ')]">
<xsl:value-of select="generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="fn-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/fn ')]">
<xsl:value-of select="generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="draft-comment-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/draft-comment ')]">
<xsl:value-of select="generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="external-link-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/xref ') or contains(@class, ' topic/link ')][@scope = 'external']">
<xsl:value-of select="generate-id(.)"/>
</xsl:for-each>
</xsl:variable>

<xsl:template match="/">
<xsl:variable name="content" as="document-node()">
<xsl:document>
<xsl:apply-templates select="node()" mode="flatten"/>
</xsl:document>
</xsl:variable>
<xsl:variable name="lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/ol ') or contains(@class, ' topic/ul ') or contains(@class, ' topic/sl ')]">
<xsl:value-of select="x:generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="image-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/image ')]">
<xsl:value-of select="x:generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="fn-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/fn ')]">
<xsl:value-of select="x:generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="draft-comment-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/draft-comment ')] |
$content//processing-instruction('oxy_comment_start')">
<xsl:value-of select="x:generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="external-link-lists" as="xs:string*">
<xsl:for-each select="$content//*[contains(@class, ' topic/xref ') or contains(@class, ' topic/link ')][@scope = 'external']">
<xsl:value-of select="x:generate-id(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="$content" mode="number">
<xsl:with-param name="lists" select="$lists" tunnel="yes"/>
<xsl:with-param name="image-lists" select="$image-lists" tunnel="yes"/>
Expand All @@ -50,46 +50,55 @@
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@xtrc | @xtrf | *[contains(@class, '- topic/required-cleanup ')]" mode="number" priority="1000"/>
<xsl:template match="(:@xtrc | @xtrf | :)*[contains(@class, '- topic/required-cleanup ')]" mode="number" priority="1000"/>

<!-- number -->

<xsl:template match="*[contains(@class, ' topic/image ')]" mode="number">
<xsl:param name="image-lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:image-number" select="index-of($image-lists, generate-id(.)) + 100"/>
<xsl:attribute name="x:image-number" select="index-of($image-lists, x:generate-id(.)) + 100"/>
<xsl:apply-templates select="@* | node()" mode="number"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/fn ')]" mode="number">
<xsl:param name="fn-lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:fn-number" select="index-of($fn-lists, generate-id(.)) + 100"/>
<xsl:attribute name="x:fn-number" select="index-of($fn-lists, x:generate-id(.)) + 100"/>
<xsl:apply-templates select="@* | node()" mode="number"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/ol ') or contains(@class, ' topic/ul ') or contains(@class, ' topic/sl ')]" mode="number">
<xsl:param name="lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:list-number" select="index-of($lists, generate-id(.)) + 100"/>
<xsl:attribute name="x:list-number" select="index-of($lists, x:generate-id(.)) + 100"/>
<xsl:apply-templates select="@* | node()" mode="number"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/draft-comment ')]" mode="number">
<xsl:param name="draft-comment-lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:draft-comment-number" select="index-of($draft-comment-lists, generate-id(.)) + 100"/>
<xsl:attribute name="x:draft-comment-number" select="index-of($draft-comment-lists, x:generate-id(.)) + 100"/>
<xsl:apply-templates select="@* | node()" mode="number"/>
</xsl:copy>
</xsl:template>
<xsl:template match="processing-instruction('oxy_comment_start')" mode="number">
<xsl:param name="draft-comment-lists" as="xs:string*" tunnel="yes"/>
<xsl:processing-instruction name="{name()}">
<xsl:text>draft-comment-number="</xsl:text>
<xsl:value-of select="index-of($draft-comment-lists, x:generate-id(.)) + 100"/>
<xsl:text>" </xsl:text>
<xsl:value-of select="."/>
</xsl:processing-instruction>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/xref ') or contains(@class, ' topic/link ')][@scope = 'external']" mode="number">
<xsl:param name="external-link-lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:external-link-number" select="index-of($external-link-lists, generate-id(.)) + 100"/>
<xsl:attribute name="x:external-link-number" select="index-of($external-link-lists, x:generate-id(.)) + 100"/>
<xsl:apply-templates select="@* | node()" mode="number"/>
</xsl:copy>
</xsl:template>
Expand All @@ -104,7 +113,9 @@

<xsl:template match="*[contains(@class, ' topic/topic ')]"
mode="number">
<xsl:param name="draft-comment-lists" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:attribute name="x:draft-comment-number" select="index-of($draft-comment-lists, x:generate-id(.)) + 100"/>
<xsl:for-each select="key('map-id', @id)[1]">
<xsl:if test="empty(ancestor-or-self::*[self::*[contains(@class, ' bookmap/frontmatter ') or
contains(@class, ' bookmap/backmatter ')] or
Expand Down
2 changes: 1 addition & 1 deletion docx/word/document.link.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
</w:rPr>
<w:instrText xml:space="preserve">
<xsl:text> NOTEREF </xsl:text>
<xsl:value-of select="concat($bookmark-prefix.note, generate-id($target))"/>
<xsl:value-of select="concat($bookmark-prefix.note, x:generate-id($target))"/>
<xsl:text> \h </xsl:text>
</w:instrText>
</w:r>
Expand Down
10 changes: 10 additions & 0 deletions docx/word/document.root.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
<xsl:apply-templates select="." mode="body"/>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="root">
<xsl:apply-templates select="."/>
</xsl:template>

<xsl:variable name="body-section" as="node()*">
<xsl:for-each select="$template/w:document/w:body/w:sectPr[position() = last()]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>

<xsl:template match="*[contains(@class, ' map/map ')]" mode="body">
<xsl:apply-templates select="*[contains(@class, ' topic/topic ')]"/>
</xsl:template>
Expand Down
2 changes: 1 addition & 1 deletion docx/word/document.toc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="x:toc">
<xsl:param name="depth" select="count(ancestor-or-self::*[contains(@class, ' topic/topic ')])" as="xs:integer"/>
<xsl:param name="prefix" as="node()*"/>
<xsl:variable name="target" select="concat($bookmark-prefix.toc, generate-id())" as="xs:string"/>
<xsl:variable name="target" select="concat($bookmark-prefix.toc, x:generate-id())" as="xs:string"/>
<xsl:variable name="style-numbered" as="xs:boolean"
select="exists($styles/w:styles/w:style[@w:styleId = concat('Heading', $depth)]/w:pPr/w:numPr)"/>
<w:p>
Expand Down
60 changes: 51 additions & 9 deletions docx/word/document.topic.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<xsl:param name="prefix" as="xs:string"/>
<xsl:param name="node" as="element()"/>

<xsl:variable name="name" select="concat($prefix, generate-id($node))"/>
<xsl:variable name="name" select="concat($prefix, x:generate-id($node))"/>
<xsl:if test="string-length($name) gt 40">
<xsl:message terminate="yes">FATAL: Bookmark <xsl:value-of select="$name"/> longer than 40 characters</xsl:message>
</xsl:if>
Expand All @@ -129,33 +129,33 @@
<xsl:param name="node" select=".[@id]" as="element()?"/>
<xsl:param name="type" as="xs:string?" select="()"/>
<xsl:if test="exists($node)">
<w:bookmarkStart w:id="ref_{$type}{generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.ref, $type), $node)}"/>
<w:bookmarkStart w:id="toc_{$type}{generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.toc, $type), $node)}"/>
<w:bookmarkStart w:id="ref_{$type}{x:generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.ref, $type), $node)}"/>
<w:bookmarkStart w:id="toc_{$type}{x:generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.toc, $type), $node)}"/>
</xsl:if>
</xsl:template>

<xsl:template name="end-bookmark">
<xsl:param name="node" select=".[@id]" as="element()?"/>
<xsl:param name="type" as="xs:string?" select="()"/>
<xsl:if test="exists($node)">
<w:bookmarkEnd w:id="ref_{$type}{generate-id($node)}"/>
<w:bookmarkEnd w:id="toc_{$type}{generate-id($node)}"/>
<w:bookmarkEnd w:id="ref_{$type}{x:generate-id($node)}"/>
<w:bookmarkEnd w:id="toc_{$type}{x:generate-id($node)}"/>
</xsl:if>
</xsl:template>

<xsl:template name="start-bookmark-number">
<xsl:param name="node" select=".[@id]" as="element()?"/>
<xsl:param name="type" as="xs:string?" select="()"/>
<xsl:if test="exists($node)">
<w:bookmarkStart w:id="num_{$type}{generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.num, $type), $node)}"/>
<w:bookmarkStart w:id="num_{$type}{x:generate-id($node)}" w:name="{x:bookmark-name(concat($bookmark-prefix.num, $type), $node)}"/>
</xsl:if>
</xsl:template>

<xsl:template name="end-bookmark-number">
<xsl:param name="node" select=".[@id]" as="element()?"/>
<xsl:param name="type" as="xs:string?" select="()"/>
<xsl:if test="exists($node)">
<w:bookmarkEnd w:id="num_{$type}{generate-id($node)}"/>
<w:bookmarkEnd w:id="num_{$type}{x:generate-id($node)}"/>
</xsl:if>
</xsl:template>

Expand Down Expand Up @@ -971,9 +971,9 @@
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/fn ')]" mode="x:get-footnote-reference">
<w:bookmarkStart w:id="note_{generate-id(.)}" w:name="{x:bookmark-name($bookmark-prefix.note, .)}"/>
<w:bookmarkStart w:id="note_{x:generate-id(.)}" w:name="{x:bookmark-name($bookmark-prefix.note, .)}"/>
<w:footnoteReference w:id="{@x:fn-number}"/>
<w:bookmarkEnd w:id="note_{generate-id()}"/>
<w:bookmarkEnd w:id="note_{x:generate-id(.)}"/>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/draft-comment ')]">
Expand All @@ -996,6 +996,48 @@
<w:pStyle w:val="CommentText"/>
</xsl:template>

<xsl:template match="processing-instruction('oxy_comment_start')">
<xsl:if test="$debug">
<xsl:variable name="attributes" as="element()">
<res>
<xsl:apply-templates select="." mode="x:parse-pi"/>
</res>
</xsl:variable>
<w:commentRangeStart w:id="{$attributes/@draft-comment-number}"/>
<xsl:choose>
<xsl:when test="x:block-content(..)">
<w:commentReference w:id="{$attributes/@draft-comment-number}"/>
</xsl:when>
<xsl:otherwise>
<w:r>
<w:rPr>
<w:rStyle w:val="CommentReference"/>
</w:rPr>
<w:commentReference w:id="{$attributes/@draft-comment-number}"/>
</w:r>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template match="processing-instruction('oxy_comment_end')">
<xsl:if test="$debug">
<xsl:variable name="start" select="preceding::processing-instruction('oxy_comment_start')[1]" as="processing-instruction()"/>
<xsl:variable name="attributes" as="element()">
<res>
<xsl:apply-templates select="$start" mode="x:parse-pi"/>
</res>
</xsl:variable>
<w:commentRangeEnd w:id="{$attributes/@draft-comment-number}"/>
</xsl:if>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/draft-comment ')] |
processing-instruction('oxy_comment_start')"
mode="block-style">
<w:pStyle w:val="CommentText"/>
</xsl:template>

<xsl:template match="*[contains(@class, ' topic/indexterm ')]"/>

<xsl:template match="*[contains(@class,' topic/term ')]" name="topic.term">
Expand Down
14 changes: 13 additions & 1 deletion docx/word/document.utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
contains($class, ' topic/fig ') or
contains($class, ' topic/li ') or
contains($class, ' topic/sli ') or
contains($class, ' topic/dt ') or
(:contains($class, ' topic/dt ') or:)
contains($class, ' topic/dd ') or
contains($class, ' topic/itemgroup ') or
contains($class, ' topic/draft-comment ') or
Expand Down Expand Up @@ -261,6 +261,18 @@
</xsl:copy>
</xsl:template>

<xsl:function name="x:generate-id" as="xs:string">
<xsl:param name="node" as="node()"/>
<!--xsl:choose>
<xsl:when test="$node/self::*/@id">
<xsl:value-of select="$node/@id"/>
</xsl:when>
<xsl:otherwise-->
<xsl:value-of select="generate-id($node)"/>
<!--/xsl:otherwise>
</xsl:choose-->
</xsl:function>

<!-- PI -->

<xsl:template match="processing-instruction()" mode="x:parse-pi" as="attribute()*">
Expand Down
Loading

0 comments on commit b590295

Please sign in to comment.