Commit cdf95c37 authored by Alex Theg's avatar Alex Theg

Merge branch 'staging' into 'master'

Staging

See merge request !2
parents a5d2f1a9 d8872bd7
<?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"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="transformation-sequence">
<xsw:transform version="3.0">detect-numbered-lists.xsl</xsw:transform>
<xsw:transform version="3.0">itemize-detected-lists.xsl</xsw:transform>
<xsw:transform version="3.0">scrub-literal-numbering-lists.xsl</xsw:transform>
</xsl:variable>
<!-- Dummy template quiets anxious XSLT engines when HTML is provided as input. -->
<xsl:template match="/html:html" xmlns:html="http://www.w3.org/1999/xhtml">
<xsl:next-match/>
</xsl:template>
<!-- traps the root node of the source and passes it down the chain of transformation references -->
<xsl:template match="/">
<xsl:variable name="source" select="."/>
<xsl:iterate select="$transformation-sequence/*">
<xsl:param name="sourcedoc" select="$source" as="document-node()"/>
<xsl:on-completion select="$sourcedoc"/>
<xsl:next-iteration>
<xsl:with-param name="sourcedoc">
<xsl:apply-templates select=".">
<xsl:with-param name="sourcedoc" select="$sourcedoc"/>
</xsl:apply-templates>
</xsl:with-param>
</xsl:next-iteration>
</xsl:iterate>
</xsl:template>
<xsl:template match="xsw:transform">
<xsl:param name="sourcedoc" as="document-node()"/>
<xsl:variable name="xslt-spec" select="."/>
<xsl:variable name="runtime" select="map {
'stylesheet-location' : string($xslt-spec),
'source-node' : $sourcedoc }" />
<!-- The function returns a map; primary results are under 'output'
unless a base output URI is given
https://www.w3.org/TR/xpath-functions-31/#func-transform -->
<xsl:sequence select="transform($runtime)?output"/>
</xsl:template>
<!-- Not knowing any better, we simply pass along. -->
<xsl:template match="*">
<xsl:param name="sourcedoc" as="document-node()"/>
<xsl:sequence select="$sourcedoc"/>
</xsl:template>
</xsl:stylesheet>
\ 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"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<!--identity template-->
<!--The first template just says "keep going". It matches any time a node is processed, for which there is no better template.
In this stylesheet it is used for everything except that div, which wraps the sequence of elements that are to be grouped. (The first grouping is between lists and not-lists, then lists are subgrouped as well.)-->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- This comes out of XSweet. -->
<xsl:template match="div[@class='docx-body']">
<xsl:copy>
<xsl:apply-templates select="@*"/> <!--the select copies the docx-body div attribute (class="docx-body"). w/o it the div gets copied but not the class-->
<xsl:call-template name="detect-lists"/> <!--calls detect-lists on all the children of <div class="docx-body">-->
</xsl:copy>
</xsl:template>
<!--detect-list template emits a sequence of groups, each containing a cluster of elements belonging to a list.
Unmarked list detection doesn't consider list level: `<xsw:list>`s get @level 0, although list item retains its `data-xsweet-list-level` attribute
Grouping key is true() for nominal list items, false if not.-->
<xsl:template name="detect-lists">
<xsl:for-each-group select="*" group-adjacent="xsw:is-list(.)">
<xsl:choose>
<!--lists must have at least 2 adjacent <p>s that look like list items-->
<xsl:when test="current-grouping-key() and count(current-group()) gt 1">
<xsl:call-template name="tag-lists"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="tag-lists">
<xsw:list level="0">
<xsl:apply-templates select="current-group()"/>
</xsw:list>
</xsl:template>
<xsl:function name="xsw:is-list" as="xs:boolean?">
<xsl:param name="whose" as="element()"/>
<!--list detected if paragraph matches: any amt of ws at start + digits + a period + at least one space-->
<xsl:sequence select="matches($whose,'^\s*\d+\.\s')"/>
</xsl:function>
</xsl:stylesheet>
\ 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"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
<!-- Redundant match silences noisy XSLT engines -->
<xsl:template match="node() | @* | html:html" xmlns:html="http://www.w3.org/1999/xhtml">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- Groups can be unwrapped since the induced list structure takes care of everything. -->
<xsl:template match="xsw:list">
<ol>
<xsl:for-each-group select="*" group-starting-with="p">
<li>
<xsl:apply-templates select="current-group()"/>
</li>
</xsl:for-each-group>
</ol>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="detect-numbered-lists.xsl"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsw="http://coko.foundation/xsweet"
>
<x:scenario>
<x:label>Basic</x:label>
<x:context>
<div class="docx-body">
<p>Not inside a list</p>
<p>1. Here's a list.</p>
<p>2. With a second item.</p>
<p>3. And a third like like this.</p>
</div>
</x:context>
<x:expect label="as list items">
<div class="docx-body">
<p>Not inside a list</p>
<xsw:list level="0" >
<p>1. Here's a list.</p>
<p>2. With a second item.</p>
<p>3. And a third like like this.</p>
</xsw:list>
</div>
</x:expect>
</x:scenario>
</x:description>
<?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"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<!-- find all li:p s and scrub the leading numeral(s) + . + ws -->
<xsl:template match="li/p">
<xsl:value-of select='replace(., "^\s*\d+\.\s+", "")'/>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
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