閑話休題: Sequenceをパラメータとして使う (2)

(続き)
 
fo:blockとfo:inlineにWordMLから変換した属性をつけるのがポイントです.それにattribute()*のsequenceのパラメータを使用します.スタイルシートはちょっと長いですが次のようになります.
 
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
    xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:tmf="http://www.sample.org/tmakita/function"
    exclude-result-prefixes="xs w wx tmf" >
<xsl:variable name="styleElem" select="/w:wordDocument/w:styles"/>
<xsl:template match="*">
    <xsl:apply-templates/>
</xsl:template>
<xsl:template match="w:wordDocument">
    <xsl:apply-templates select="w:body"/>
</xsl:template>
<xsl:template match="w:tc">
    <xsl:variable name="tblStyle" select="string(ancestor::w:tbl/w:tblPr/w:tblStyle/@w:val)" as="xs:string"/>
    <xsl:variable name="pPrTblInheritd" select="if ($tblStyle ne '') then tmf:processPStyle($tblStyle) else ()" as="attribute()*"/>
    <xsl:variable name="rPrTblInheritd" select="if ($tblStyle ne '') then tmf:processRStyle($tblStyle) else ()" as="attribute()*"/>
    <xsl:apply-templates>
        <xsl:with-param name="pPrInherited" select="$pPrTblInheritd"/>
        <xsl:with-param name="rPrInherited" select="$rPrTblInheritd"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="w:p">
    <xsl:param name="pPrInherited" as="attribute()*" select="()"/>
    <xsl:param name="rPrInherited" as="attribute()*" select="()"/>
    <xsl:variable name="thisParagraphAttribute" as="attribute()*">
        <xsl:copy-of select="$pPrInherited"/>
        <xsl:choose>
            <xsl:when test="w:pPr">
                <xsl:apply-templates select="w:pPr"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="tmf:processPStyle('Normal')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="thisRunAttribute" as="attribute()*">
        <xsl:copy-of select="$rPrInherited"/>
        <xsl:variable name="pStyle" select="if (w:pPr/w:pStyle) then w:pPr/w:pStyle/@w:val else 'Normal'"/>
        <xsl:copy-of select="tmf:processRStyle($pStyle)"/>
    </xsl:variable>
    <fo:block>
        <xsl:copy-of select="$thisParagraphAttribute"/>
        <xsl:apply-templates select="*[name()!='w:pPr']">
            <xsl:with-param name="rPrInherited" select="$thisRunAttribute"/>
        </xsl:apply-templates>
    </fo:block>
</xsl:template>
<xsl:template match="w:r">
    <xsl:param name="rPrInherited" as="attribute()*" select="()"/>
    <xsl:variable name="thisRunAttribute" as="attribute()*">
        <xsl:copy-of select="$rPrInherited"/>
        <xsl:if test="w:rPr">
            <xsl:apply-templates select="w:rPr"/>
        </xsl:if>
    </xsl:variable>
    <xsl:apply-templates select="*[name()!='w:rPr']">
        <xsl:with-param name="rPrInherited" select="$thisRunAttribute"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="w:t">
    <xsl:param name="rPrInherited" as="attribute()*" select="()"/>
    <fo:inline>
        <xsl:copy-of select="$rPrInherited"/>
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>
<xsl:template match="w:pPr">
    <xsl:apply-templates select="*"/>
    <xsl:if test="not(w:pStyle)">
        <xsl:copy-of select="tmf:processPStyle('Normal')"/>
    </xsl:if>
</xsl:template>
<xsl:template match="w:pPr" mode="PROCESS_STYLE">
    <xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="w:rPr">
    <xsl:apply-templates select="*"/>
</xsl:template>
<xsl:function name="tmf:processPStyle" as="attribute()*">
    <xsl:param name="prmStyle" as="xs:string"/>
    <xsl:apply-templates select="$styleElem/w:style[@w:styleId=$prmStyle]/w:pPr" mode="PROCESS_STYLE"/>
</xsl:function>
<xsl:function name="tmf:processRStyle" as="attribute()*">
    <xsl:param name="prmStyle" as="xs:string"/>
    <xsl:apply-templates select="$styleElem/w:style[@w:styleId=$prmStyle]/w:rPr"/>
</xsl:function>
(続く)