Commit bd9755f2 authored by Alex Theg's avatar Alex Theg
Browse files

add list detection

parent 8392afbd
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
<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:apply-templates select="node() | @*"/>
<!-- This comes out of XSweet. -->
<xsl:template match="div[@class='docx-body']">
<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">-->
<!--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(.)=true()">
<xsl:when test="current-grouping-key() and count(current-group()) gt 1">
<xsl:call-template name="tag-lists"/>
<xsl:apply-templates select="current-group()"/>
<xsl:template name="tag-lists">
<xsw:list level="0">
<xsl:apply-templates select="current-group()"/>
<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 (inc tabs), digits + a period + at least one more spaces-->
<xsl:variable name="list-assignment" select="matches($whose,'^\s?\t?\d+\.\s?')"/>
<xsl:sequence select="xs:boolean($list-assignment)"/>
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