Re: [xsl] From WordprocessingML inline styles to nested inline elements

Subject: Re: [xsl] From WordprocessingML inline styles to nested inline elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 21 Mar 2007 15:22:33 GMT
> In my output, however, the inline styles should nest, and moreover, nest 
> in a particular order:

something like

$ saxon wp1.xml wp1.xsl
<?xml version="1.0" encoding="utf-8"?><run><b><i>This is text in bold and italic.</i></b></run>
davidc@souldern /c/tmp
$ cat wp1.xml
<w:r xmlns:w="data:,w">
   <w:rPr>
     <w:i/>
     <w:b/>
   </w:rPr>
   <w:t>This is text in bold and italic.</w:t>
</w:r>

$ cat wp1style.xml 

<style_nesting>
   <b><i><u/></i></b>
</style_nesting>


$ cat wp1.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:w="data:,w"
 exclude-result-prefixes="w">

<xsl:variable name="s" select="document('wp1style.xml')/style_nesting"/>

<xsl:template match="w:r">
  <run>
    <xsl:apply-templates mode="s" select="$s">
      <xsl:with-param name="t" select="w:t"/>
      <xsl:with-param name="p" select="w:rPr"/>
    </xsl:apply-templates>
  </run>
</xsl:template>


<xsl:template match="*" mode="s">
  <xsl:param name="t"/>
  <xsl:param name="p"/>
  <xsl:choose>
    <xsl:when test="$p/*[local-name()=local-name(current())]">
      <xsl:copy>
        <xsl:apply-templates mode="s" select="*">
          <xsl:with-param name="p" select="$p"/>
          <xsl:with-param name="t" select="$t"/>
        </xsl:apply-templates>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates mode="s" select="*">
        <xsl:with-param name="p" select="$p"/>
        <xsl:with-param name="t" select="$t"/>
      </xsl:apply-templates>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:if test="not(*)">
    <xsl:value-of select="$t"/>
  </xsl:if>
</xsl:template>
  



</xsl:stylesheet>

Current Thread