Commit cb47419d authored by Wendell Piez's avatar Wendell Piez

Removing XSweet version in favor of XSweet/HTMLevator version

parent 5b6475be
<?xml version="1.0" encoding="UTF-8"?>
<div id="header-map" class="by-regex">
<!-- @class values and contents are read as regular expressions.
A given class must match (as a regex) a class 'token' in the input, anchored at beginning and end, case-insensitive
i.e. 'head1?' matches 'head1' and 'head' and 'HEAD' but not 'bighead'
Given contents are tested case-sensitively, and not anchored
so \S matches any string with non-whitespace (i.e. just about anything) -->
<!-- Mapping the common "Header 1" and its kin -->
<h1 class="h(ead|eader|ing)\s*1">\S</h1>
<h2 class="h(ead|eader|ing)\s*2">\S</h2>
<h3 class="h(ead|eader|ing)\s*3">\S</h3>
<h4 class="h(ead|eader|ing)\s*4">\S</h4>
<h5 class="h(ead|eader|ing)\s*5">\S</h5>
<h6 class="h(ead|eader|ing)\s*6">\S</h6>
<!-- Mapping Subtitle -->
<h2 class="[Ss]ubtitle">\S</h2>
<!-- Mapping any paragraph whose content is 'Introduction' -->
<h2>^Introduction\s*$</h2>
</div>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:xsw="http://coko.foundation/xsweet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
type="xsw:html-header-promote" name="html-header-promote">
<p:input port="source" primary="true"/>
<p:input port="parameters" kind="parameter"/>
<p:output port="_Z_FINAL" primary="true">
<p:pipe port="result" step="final"/>
</p:output>
<p:output port="_A_digested" primary="false">
<p:pipe port="result" step="digest-paragraphs"/>
</p:output>
<p:output port="_B_headers-promoted" primary="false">
<p:pipe port="result" step="apply-the-header-mapping-xslt"/>
</p:output>
<p:output port="_X_escalator-xslt" primary="false">
<p:pipe port="result" step="escalator-xslt"/>
</p:output>
<p:serialization port="_A_digested" indent="true" omit-xml-declaration="true"/>
<p:serialization port="_B_headers-promoted" indent="true" omit-xml-declaration="true"/>
<p:serialization port="_X_escalator-xslt" indent="true" omit-xml-declaration="true"/>
<p:serialization port="_Z_FINAL" indent="true" omit-xml-declaration="true"/>
<p:identity name="in"/>
<!-- First, reduce the input to a "weighted profile" of its paragraph styles -->
<p:xslt name="digest-paragraphs">
<p:input port="stylesheet">
<p:document href="digest-paragraphs.xsl"/>
</p:input>
</p:xslt>
<!-- Then generate an XSLT stylesheet from it -->
<p:xslt name="escalator-xslt">
<p:input port="stylesheet">
<p:document href="make-header-escalator-xslt.xsl"/>
</p:input>
</p:xslt>
<!-- This is the loop! where we apply the stylesheet we have generated -->
<p:xslt name="apply-the-header-mapping-xslt">
<p:input port="source">
<p:pipe port="result" step="in"/>
</p:input><p:input port="stylesheet">
<p:pipe port="result" step="escalator-xslt"/>
</p:input>
</p:xslt>
<p:identity name="final"/>
<!--<p:xslt name="">
<p:input port="stylesheet">
<p:inline>
<xsl:stylesheet version="2.0"
xmlns="http://www.w3.org/1999/xhtml"
xpath-default-namespace="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all"/>
</p:inline>
</p:input>
</p:xslt>-->
</p:declare-step>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsw="http://coko.foundation/xsweet"
xmlns="http://www.w3.org/1999/xhtml"
xpath-default-namespace="http://www.w3.org/1999/xhtml">
<xsl:output indent="yes"/>
<!-- Example input - all these have been identified as headers -
<div class="hX">
<div class="level-group">
<p style="font-weight: bold"/>
</div>
<div class="hX">
<p style="font-size: 10pt; font-weight: bold"/>
</div>
<div class="hX">
<p style="font-size: 10pt; font-style: italic; font-weight: bold"/>
</div>
</div>
-->
<xsl:namespace-alias stylesheet-prefix="xsw" result-prefix="xsl"/>
<xsl:param name="debug-mode" as="xs:string">silent</xsl:param>
<!-- Note that generated stylesheet will error if $extra-match-criteria is anything but an XPath filter expression
i.e. '[ booleanExp ]' (with square brackets).
Exposing it as a parameter isn't recommended unless we can defend against arbitrary XPath injection. -->
<xsl:variable name="extra-match-criteria">[empty(ancestor::table|ancestor::li)][ancestor::*/@class='docx-body'][string-length(.) &lt;= 200][matches(.,'\S')]</xsl:variable>
<xsl:template match="body">
<!-- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsw="http://coko.foundation/xsweet"
xmlns="http://www.w3.org/1999/xhtml"
-->
<xsw:stylesheet version="3.0"
xpath-default-namespace="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all">
<xsw:output method="xml" omit-xml-declaration="yes"/>
<xsw:template match="node() | @* | /html">
<xsw:copy>
<xsw:apply-templates select="node() | @*"/>
</xsw:copy>
</xsw:template>
<xsl:apply-templates select="div[@class='grouped']/div[@class='hX']/*" mode="xslt-produce"/>
<xsl:if test="not($debug-mode='silent')">
<xsw:variable name="in">
<xsl:copy-of select="div"/>
</xsw:variable>
</xsl:if>
</xsw:stylesheet>
</xsl:template>
<!-- Template writes XSLT templates -->
<xsl:template match="div[@class='hX']/*" mode="xslt-produce">
<xsl:variable name="match">
<xsl:value-of select="local-name()"/>
<xsl:for-each select="@class">
<xsl:text>[@class/tokenize(.,'\s+') = '</xsl:text>
<xsl:value-of select="."/>
<xsl:text>']</xsl:text>
</xsl:for-each>
<xsl:for-each select="@style/tokenize(.,'\s*;\s*')">
<xsl:text>[@style/tokenize(.,'\s*;\s*') = '</xsl:text>
<xsl:value-of select="."/>
<xsl:text>']</xsl:text>
</xsl:for-each>
<!-- If font-style was not given explicity it must be missing to match. -->
<xsl:if test="empty(@style/tokenize(.,'\s*;\s*')[starts-with(.,'font-size:')])">
<xsl:text>[empty(@style/tokenize(.,'\s*;\s*')[starts-with(.,'font-size:')])]</xsl:text>
</xsl:if>
<xsl:if test="@data-always-caps='true'">
<xsl:text>[.=upper-case(.)]</xsl:text>
</xsl:if>
<xsl:copy-of select="$extra-match-criteria"/>
</xsl:variable>
<xsw:template match="{$match}">
<xsl:variable name="h-level" select="count(..|../following-sibling::div[@class='hX'])"/>
<xsl:attribute name="priority" select="count(. | preceding-sibling::* | ../preceding-sibling::div[@class='hX']/*)"/>
<xsw:element name="h{$h-level}">
<xsw:copy-of select="@*"/>
<!--<xsw:comment> was <xsl:value-of select="$match"/> </xsw:comment>-->
<xsw:apply-templates/>
</xsw:element>
</xsw:template>
</xsl:template>
</xsl:stylesheet>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment