Character Maps
Version: | 1.0.0 |
---|---|
Date: | 2006-04 |
Changes: | Initial version. |
The ePublisher 9.2 builds support a new character mapping feature. It is not equivalent to the Publisher 2003 implementation at this time as it lacks a GUI. It is a low-level hook to enable implementation of such a GUI feature in the future.
Elements
It is implemented using the following elements:
<wwexsldoc:ResetMappingContext> ... </wwexsldoc:ResetMappingContext> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">&nbsp;</wwexsldoc:MapEntry> ... ... </wwexsldoc:MappingContext>
Scenarios
Here's how it works inside your XSL transforms.
Create your XSL code:
<xsl:template match="wwdoc:Paragraph"> <!-- Do something really cool here! --> <!-- --> </xsl:template>
Define a "MappingContext" to use:
<xsl:template match="wwdoc:Paragraph"> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">&nbsp;</wwexsldoc:MapEntry> <!-- Do something really cool here! --> <!-- --> </wwexsldoc:MappingContext> </xsl:template>
Mapping contexts are cumulative. Each one you define extends the previous one:
<xsl:template match="wwdoc:Paragraph"> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">&nbsp;</wwexsldoc:MapEntry> <!-- Do something really cool here! --> <!-- --> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match="ߦ">Bullet</wwexsldoc:MapEntry> <!-- Do something amazingly cool here! --> <!-- --> </wwexsldoc:MappingContext> <!-- Do something pretty cool here! --> <!-- --> </wwexsldoc:MappingContext> </xsl:template>
The lower context wins if it redefines a map entry:
<xsl:template match="wwdoc:Paragraph"> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">&nbsp;</wwexsldoc:MapEntry> <!-- Do something really cool here! --> <!-- --> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">NoBreaks</wwexsldoc:MapEntry> <!-- Do something amazingly cool here! --> <!-- --> </wwexsldoc:MappingContext> <!-- Do something pretty cool here! --> <!-- --> </wwexsldoc:MappingContext> </xsl:template>
Mapping contexts are cumulative, but you can reset them:
<xsl:template match="wwdoc:Paragraph"> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match=" ">&nbsp;</wwexsldoc:MapEntry> <!-- Do something really cool here! --> <!-- --> <wwexsldoc:ResetMappingContext> <wwexsldoc:MappingContext> <wwexsldoc:MapEntry match="ߦ">Bullet</wwexsldoc:MapEntry> <!-- Do something amazingly cool here! --> <!-- --> </wwexsldoc:MappingContext> </wwexsldoc:ResetMappingContext> <!-- Do something pretty cool here! --> <!-- --> </wwexsldoc:MappingContext> </xsl:template>
Notes
This implementation was originally designed to support mapping single characters. As it turns out, the implementation actually supports mapping arbitrary strings. While string mapping is fully supported, please be aware that you may encounter unintended side-effects with string matches. The reason is that we will take the longest match and apply that. So, one attempted to match:
_ --> Apple
and:
_` --> Alphabet
then in the sequence:
]^_`a
you would get:
]^Alphabeta
instead of:
]^Apple`a
The replacement implementation does not recognize word boundaries.
Alternatively, you can also use the existing extension method:
wwstring:ReplaceWithExpression()
to perform regular expression based replacements.
Finally, this replacement mechanism only works for unescaped text. Any text placed inside of:
<wwexsldoc:Text> ... </wwexsldoc:Text>
elements will not be routed through the replacement algorithm, similar to XSL 2.0's character maps.
This implementation was chosen in place of XSL 2.0 character maps because:
- XSL 2.0 character maps apply to an entire file
- No way to modify how Webdings, Symbol, Zapf Dingbats fonts are mapped independent of the master character map
- Named character maps are problematic to use when they might be redefined or extended in different mapping contexts
Named character maps can be simulated with the current implementation at a slight performance cost. Ease of implementation and overall flexibility were deemed more important than this marginal performance loss.