<!---->
<
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="
xs tps">
<
xd:
doc type="
stylesheet">
<
xd:
short>
Contains conversion logic for character and soft styles
</
xd:
short>
<
xd:
cvsId>
$Revision$</
xd:
cvsId>
</
xd:
doc>
<!---->
<
xsl:
template match="
node()"
mode="
set-c-type" />
<
xsl:
template match="
element()[tps:is-style-element(.)][tps:has-custom-c-type(.)]"
priority="
10">
<
tps:
c type="
{tps:get-custom-c-type(.)}">
<
xsl:
apply-templates />
</
tps:
c>
</
xsl:
template>
<
xsl:
function name="
tps:has-custom-c-type"
as="
xs:boolean">
<
xsl:
param name="
el"
as="
element()" />
<
xsl:
sequence select="
exists(tps:get-custom-c-type($el))" />
</
xsl:
function>
<
xsl:
function name="
tps:get-custom-c-type"
as="
xs:string?">
<
xsl:
param name="
el"
as="
element()" />
<
xsl:
variable name="
result"
as="
xs:string?">
<
xsl:
apply-templates select="
$el"
mode="
set-c-type" />
</
xsl:
variable>
<
xsl:
sequence select="
$result" />
</
xsl:
function>
<
xsl:
template match="
bold">
<
tps:
style type="
{$style.type.bold}">
<
xsl:
apply-templates />
</
tps:
style>
</
xsl:
template>
<
xsl:
template match="
italic">
<
tps:
style type="
{$style.type.italic}">
<
xsl:
apply-templates />
</
tps:
style>
</
xsl:
template>
<
xsl:
template match="
underline">
<
tps:
style type="
{$style.type.underline}">
<
xsl:
apply-templates />
</
tps:
style>
</
xsl:
template>
<
xsl:
template match="
sub">
<
tps:
style type="
{$style.type.sub}">
<
xsl:
apply-templates />
</
tps:
style>
</
xsl:
template>
<
xsl:
template match="
sup">
<
tps:
style type="
{$style.type.sup}">
<
xsl:
apply-templates />
</
tps:
style>
</
xsl:
template>
<
xsl:
function name="
tps:select-style"
as="
element()?">
<
xsl:
param name="
el"
as="
element()" />
<
xsl:
param name="
styles-to-match"
as="
xs:string+" />
<
xsl:
variable name="
contextual-styles"
select="
tps:get-contextual-styles($el)" />
<
xsl:
sequence select="
if (exists($contextual-styles)) then $el[tps:is-subsequence($styles-to-match, $contextual-styles)] else ()" />
</
xsl:
function>
<
xsl:
function name="
tps:get-contextual-styles"
as="
xs:string*">
<
xsl:
param name="
el"
as="
element()" />
<
xsl:
variable name="
styles"
select="
$el/ancestor-or-self::*[tps:is-style-element(.)]/name()" />
<
xsl:
sequence select="
distinct-values($styles)" />
</
xsl:
function>
<
xsl:
function name="
tps:is-style-element"
as="
xs:boolean">
<
xsl:
param name="
el"
as="
element()" />
<
xsl:
sequence select="
exists($el[self::bold or self::italic or self::underline or self::sup or self::sub])" />
</
xsl:
function>
</
xsl:
stylesheet>
v