<!--

# =============================================================================

# Copyright © 2013 Typéfi Systems. All rights reserved.

#

# Unless required by applicable law or agreed to in writing, software

# is distributed on an "as is" basis, without warranties or conditions of any

# kind, either express or implied.

# =============================================================================

-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tps="http://www.typefi.com/ContentXML" xmlns:xd="http://www.pnp-software.com/XSLTdoc" version="2.0" exclude-result-prefixes="#all">





    
    <xd:doc type="stylesheet">

        
<xd:short>

            Contains list-related features: conversion of lists, recognition of list type, determination of target list paragraph styles.

        
</xd:short>

        
<xd:detail>

            To customize list paragraph types override:

            
<ul>

                
<li>mode <code>get-list-item-type</code></li>

                
<li>function <code>tps:get-list-item-p-para-type-prefix</code></li>

                
<li>function <code>tps:get-list-item-p-para-type-postfix</code></li>

            
</ul>

            and other functions according to their purpose.

            This approach allows to generate custom list styles whose name consists of multiple independent parts,

            e.g. 
<xd:xml><tps:p type="List_NUM.1.middle.single.digit" /></xd:xml>

        
</xd:detail>

        
<xd:cvsId>   $Revision$</xd:cvsId>

    
</xd:doc>






    
<xsl:template match="list[tps:is-ordered-list(.) or tps:is-bullet-list(.)]" priority="10">

        
<xsl:apply-templates select="element() except label" />

    
</xsl:template>





    
<xsl:template match="list">

        
<xsl:call-template name="display-warning">

            
<xsl:with-param name="message" select="if (empty(@list-type)) then 'A list without @list-type was found. Skipping.' else concat('''', @list-type, ''' is an unknown @list-type value. ', 'The contents of the list will be ignored.')" />

        
</xsl:call-template>

    
</xsl:template>





    
<xsl:template match="list/label">

        
<xsl:apply-templates />

        
<xsl:text></xsl:text>

    
</xsl:template>





    
<xsl:template match="list/title">

        
<tps:p type="{$list.title.para.type}">

            
<xsl:copy-of select="parent::list/@id" />

            
<xsl:apply-templates select="../label" />

        
</tps:p>

    
</xsl:template>





    
<xsl:template match="list-item">

        
<xsl:apply-templates select="element() except label" />

    
</xsl:template>





    
<xsl:template match="list/list-item/label">

        
<xsl:apply-templates />

        
<tps:t />

    
</xsl:template>





    
<xsl:template match="list/list-item/p[1]" priority="10">

        
<tps:p type="{tps:get-list-item-p-para-type(.)}">

            
<xsl:copy-of select="parent::list-item/@id" />

            
<xsl:apply-templates select="../label" />

            
<xsl:apply-templates />

        
</tps:p>

    
</xsl:template>





    
<xsl:template match="list/list-item/p">

        
<tps:p type="{tps:get-list-item-p-para-type(.)}">

            
<tps:t />

            
<xsl:apply-templates />

        
</tps:p>

    
</xsl:template>





    
<!-- @Description:  This function should be used when there is a requirement to differentiate

                        ordered lists processing. 
-->

    
<xsl:function name="tps:is-ordered-list" as="xs:boolean">

        
<xsl:param name="list" as="element(list)" />



        
<xsl:sequence select="$list/@list-type = ('order', 'alpha-upper', 'alpha-lower', 'roman-upper', 'roman-lower')" />

    
</xsl:function>





    
<!-- @Description:  Use this function to combine transformation logic for bullet list types

                        group. 
-->

    
<xsl:function name="tps:is-bullet-list" as="xs:boolean">

        
<xsl:param name="list" as="element(list)" />



        
<xsl:sequence select="$list/@list-type = ('bullet', 'simple')" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-para-type" as="xs:string">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="concat(tps:get-list-item-p-para-type-prefix($p), tps:get-list-item-p-para-type-root($p), tps:get-list-item-p-para-type-postfix($p))" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-para-type-root" as="xs:string">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="concat($list-item.p.para.type, tps:get-list-item-p-type-marker($p), tps:get-list-item-p-level-marker($p), tps:get-list-item-p-position-marker($p), tps:get-continued-list-item-p-para-type-postfix($p))" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-para-type-prefix" as="xs:string?">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="()" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-para-type-postfix" as="xs:string?">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="()" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-type-marker" as="xs:string">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:variable name="result" as="xs:string*">

            
<xsl:apply-templates select="$p" mode="get-list-item-type" />

        
</xsl:variable>



        
<xsl:sequence select="string-join($result, '')" />

    
</xsl:function>





    
<xsl:template match="list[@list-type eq 'order']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.order.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'alpha-upper']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.alpha-upper.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'alpha-lower']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.alpha-lower.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'roman-upper']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.roman-upper.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'roman-lower']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.roman-lower.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'bullet']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.bullet.marker" />

    
</xsl:template>





    
<xsl:template match="list[@list-type eq 'simple']/list-item/p" mode="get-list-item-type">

        
<xsl:sequence select="$list-item.p.simple.marker" />

    
</xsl:template>





    
<xsl:function name="tps:get-list-item-p-level-marker" as="xs:string">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="string(count($p/ancestor::list-item))" />

    
</xsl:function>





    
<xsl:function name="tps:get-list-item-p-position-marker" as="xs:string">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:variable name="result" as="xs:string*">

            
<xsl:apply-templates select="$p" mode="get-list-item-position-marker" />

        
</xsl:variable>



        
<xsl:sequence select="string-join($result, '')" />

    
</xsl:function>





    
<xsl:template match="list[tps:is-upper-level-list(.) and count(list-item) eq 1]/ list-item[count(p) eq 1]/p" mode="get-list-item-position-marker" priority="20">

        
<xsl:sequence select="$list-item.p.single.marker" />

    
</xsl:template>





    
<xsl:template match="list/list-item/p[tps:first-list-p(.)]" mode="get-list-item-position-marker" priority="10">

        
<xsl:sequence select="$list-item.p.first.marker" />

    
</xsl:template>





    
<xsl:template match="list/list-item/p[tps:last-list-p(.)]" mode="get-list-item-position-marker" priority="10">

        
<xsl:sequence select="$list-item.p.last.marker" />

    
</xsl:template>





    
<xsl:template match="list/list-item/p" mode="get-list-item-position-marker">

        
<xsl:sequence select="$list-item.p.middle.marker" />

    
</xsl:template>





    
<xsl:function name="tps:is-upper-level-list" as="xs:boolean">

        
<xsl:param name="list" as="element(list)" />



        
<xsl:sequence select="empty($list/ancestor::list)" />

    
</xsl:function>





    
<xsl:function name="tps:first-list-p" as="element(p)?">

        
<xsl:param name="p" as="element(p)" />

        
<xsl:variable name="list" select="$p/ancestor::list[last()]" />



        
<xsl:sequence select="($list//p)[1][. is $p]" />

    
</xsl:function>





    
<xsl:function name="tps:last-list-p" as="element(p)?">

        
<xsl:param name="p" as="element(p)" />

        
<xsl:variable name="list" select="$p/ancestor::list[last()]" />



        
<xsl:sequence select="($list//p)[last()][. is $p]" />

    
</xsl:function>





    
<xsl:function name="tps:get-continued-list-item-p-para-type-postfix" as="xs:string?">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="$list-item.p.continued.para.type.postfix[tps:is-continued-list-item-p($p)]" />

    
</xsl:function>





    
<xsl:function name="tps:is-continued-list-item-p" as="xs:boolean">

        
<xsl:param name="p" as="element(p)" />



        
<xsl:sequence select="exists($p/preceding-sibling::p)" />

    
</xsl:function>



</xsl:stylesheet>













































































v