<!---->
<
xsl:
stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:tps="
http://www.typefi.com/ContentXML"
xmlns:xd="
http://www.pnp-software.com/XSLTdoc"
version="
2.0"
exclude-result-prefixes="
#all">
<
xd:
doc type="
stylesheet">
<
xd:
short>
Contains conversion logic for text processing.</
xd:
short>
<
xd:
cvsId>
$Revision$</
xd:
cvsId>
<
xd:
detail>
There is two feature for processing text:<
br />
<
h4>
Charachter mapping</
h4>
For applying character and soft styles to certain symbols or unicode ranges.<
br />
There are two ways to use character re-mapping scheme: by specifying
separate characters and corresponding mappings, and by declaring whole
ranges of remapped characters. One can use @wrap attribute to insert
any matched input character sequences in the element set by the variable.<
br />
@Example:
<
xd:
xml>
<
range from="
"
to="
Ā">
<
tps:
style name="
ABC" />
</
range>
<
char values="
′ሴ䌡">
<
tps:
c type="
TNR" />
</
char>
<
char values="
′"
wrap="
true">
<
tps:
c type="
TNR" />
</
char>
</
xd:
xml>
Enables character mapping (see $character.mapping variable for the
configuration)
<
h4>
text keeps processing</
h4><
br />
For mapping text to text.<
br />
Text keeps processing has a higher priority then character
mapping. So, if $text.keeps.mapping.enabled is set to true(), the mentioned
is not applied.<
br />
@Example:
<
xd:
xml>
<
process>
<
action>
<
find text="
Standard" />
<
replace text="
"
with="
" />
<
find arabic="
yes"
roman="
yes" />
</
action>
</
process>
</
xd:
xml>
</
xd:
detail>
</
xd:
doc>
<
xsl:
template match="
text()">
<
xsl:
call-template name="
text" />
</
xsl:
template>
<
xsl:
template name="
text">
<
xsl:
sequence select="
tps:get-text-mapping-result(.)" />
</
xsl:
template>
<
xsl:
template match="
disp-formula[inline-formula/inline-graphic]/text()">
<
xsl:
call-template name="
disp-formula-text" />
</
xsl:
template>
<
xsl:
template name="
disp-formula-text">
<
xsl:
analyze-string select="
."
regex="
\s+">
<
xsl:
matching-substring>
<
tps:
s />
</
xsl:
matching-substring>
<
xsl:
non-matching-substring>
<
xsl:
sequence select="
tps:get-text-mapping-result(.)" />
</
xsl:
non-matching-substring>
</
xsl:
analyze-string>
</
xsl:
template>
<
xsl:
function name="
tps:get-text-mapping-result"
as="
node()*">
<
xsl:
param name="
text"
as="
xs:string" />
<
xsl:
variable name="
text-keeps-processed"
select="
(tps:get-text-keeps-mapping-result($text)[$text.keeps.mapping.enabled], $text)[1]" />
<
xsl:
variable name="
result"
select="
(tps:get-character-mapping-result($text-keeps-processed)[$text.character.mapping.enabled], $text-keeps-processed)[1]" />
<
xsl:
sequence select="
tps:convert-to-nodes($result)" />
</
xsl:
function>
<
xsl:
function name="
tps:convert-to-nodes"
as="
node()*">
<
xsl:
param name="
items"
as="
item()*" />
<
xsl:
for-each select="
$items">
<
xsl:
copy-of select="
if (. instance of xs:string) then tps:convert-to-text(.) else ." />
</
xsl:
for-each>
</
xsl:
function>
<
xsl:
function name="
tps:convert-to-text"
as="
text()">
<
xsl:
param name="
string"
as="
xs:string" />
<
xsl:
value-of select="
$string" />
</
xsl:
function>
</
xsl:
stylesheet>
v