One way to define the MCE semantics: XSLT

MURATA Makoto eb2m-mrt at asahi-net.or.jp
Thu Apr 12 15:16:16 CEST 2012


Dear colleagues,

I have been wondering how the semantics of MCE should be
specified.

Here is one way: a normative XSLT stylesheet.   I am not saying that this
is the best approach, but it at least deserves to be considered.

This XSLT stylesheet uses four extension functions:
me:frozen, me:ignored, me:selectable, and me:understood.

Let me:frozen be an XPath extension function such that
me:frozen(node) evalutes to true iff the node is an extension
extension element.

Let me:ignored be an XPath extension function such that
me:ignored(node) evalutes to true iff the node is an element or
attribute whose namespace is ignorable and non-understood.

let me:selectable be an XPath extension function such that
me:selectable(node) evalutes to true iff (1) this node is a Choice
element and each of the namespace specified by the Requires attribute
of this node is understood or (2) this node is a
Fallback element.

Let me:understood be an XPath extension function such that
me:understood(string) evaluates to true iff the string is a white-space
delimited list of understood namespaces.  Observe that me:undersood("")
is true.

Note: me:ignored, me:selectable, me:understood require the
configuration (i.e., a
set of understood namespaces) as an environment, while me:frozen does
not.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:me="http://purl.oclc.org/ooxml/markup-compatibility/extension-function"
    xmlns:mce="http://schemas.openxmlformats.org/markup-compatibility/2006"
    version="1.0">

    <xsl:template match="*[me:frozen(.)]">
        <xsl:copy-of select="."/>
    </xsl:template>

    <xsl:template match="*[me:ignored(.)]"/>
    <xsl:template match="@*[me:ignored(.)]"/>

    <xsl:template match="mce:AlternateContent">
        <xsl:for-each select="mce:Choice | mce:Fallback">
            <xsl:if test="me:selectable(.) and
not(me:selectable(preceding-sibling::mce:Choice))">
                <xsl:apply-templates select="*"/>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>


    <xsl:template match="*">
        <xsl:choose>
            <xsl:when test="me:understood(namespace-uri(.))">
                <xsl:copy>
                    <xsl:apply-templates
select="*|@*|processing-instruction()|comment()|text()"/>
                </xsl:copy>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="yes">Non-understood namespace
occurred</xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="@mce:MustUnderstand[not(me:understood(string(.)))]">
        <xsl:message terminate="yes">Non-understood namespace
specified by @MustUnderstand</xsl:message>
    </xsl:template>

    <xsl:template match="@*">
        <xsl:choose>
            <xsl:when test="me:understood(namespace-uri(.))">
                <xsl:copy/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="yes">Non-understood namespace
occurred</xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="text()|processing-instruction()|comment()">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

P.S.  I am now  wondering what happens when an application-defined extension
element belongs to a non-understood and non-ignorable namespace.  Frozen
or discarded?

P.S.  I suppose that @MustUnderstood cannot be specified by
mce:AlternateContent,
mce:Choice, or mce:Fallback.

-- 

Praying for the victims of the Japan Tohoku earthquake

Makoto


More information about the sc34wg4 mailing list