WordML: extract font from character style

The font of a character style (the style of a range of text, not the whole paragraph) is stored in the w:styles/w:style/w:rPr/w:rFonts/@w:ascii element, as shown in the following snapshot from XML Notepad:

To get the character font from the style name, use the following xsl:key definition:

<xsl:key name="rangefont" match="w:rFonts/@w:ascii" →
use="ancestor::w:style[@w:type = 'character']/@w:styleId" />

You should check the style type in the key definition to ensure that the key matches only the character styles.

Later on, you can use the rangefont key to check the font in a range-matching template. For example, to check whether the current range has courier font, use the following xsl:choose block:

<xsl:when test="contains(w:rPr/wx:font/@wx:val,'Courier')">
<!-- fixed-font specified in the range -->
<xsl:when test="contains(key('rangefont',w:rPr/w:rStyle/@w:val),'Courier')">
<!-- fixed-font specified in the character style -->
<!-- not a fixed font -->

No comments:

Post a Comment