Skip to content

Commit

Permalink
Merge pull request qt4cg#1530 from michaelhkay/1500-character-map-fun…
Browse files Browse the repository at this point in the history
…ction

1500 New XSLT character-map() function
  • Loading branch information
michaelhkay authored Oct 30, 2024
2 parents c58b5b8 + d1e518e commit fae0aca
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
56 changes: 56 additions & 0 deletions specifications/xslt-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,62 @@

</fos:examples>
</fos:function>

<fos:function name="character-map" prefix="fn">
<fos:signatures>
<fos:proto name="character-map" return-type="map(xs:string, xs:string)?">
<fos:arg name="name" type="xs:QName"/>
</fos:proto>
</fos:signatures>
<fos:properties>
<fos:property>deterministic</fos:property>
<fos:property dependency="character-maps">context-dependent</fos:property>
<fos:property>focus-independent</fos:property>
</fos:properties>
<fos:summary>
<p>Delivers the content of a character map declared using <elcode>xsl:character-map</elcode>.</p>
</fos:summary>
<fos:rules>

<p>The static context for a stylesheet package includes a set of named character maps. This function
delivers the content of a character map if a character map with the given name is present in the
static context of the containing package, or an empty sequence otherwise.</p>

</fos:rules>

<fos:notes>
<p>The returned character map is in a format suitable for use within the <code>$options</code>
parameter of the <xfunction>serialize</xfunction> function.</p>
</fos:notes>
<fos:examples>
<fos:example>
<!--<example>
<head>Using the <function>character-map</function> function</head>-->
<p>Consider the following character map declaration:</p>
<eg><![CDATA[
<xsl:character-map name="jsp">
<xsl:output-character character="«" string="&lt;%"/>
<xsl:output-character character="»" string="%&gt;"/>
<xsl:output-character character="§" string='"'/>
</xsl:character-map>
]]></eg>
<p>Then the result of the function call <code>character-map(xs:QName('jsp'))</code> is the map:</p>
<eg>
map {
"«": "&lt;%",
"»": "%&gt;",
"§": '"'
}
</eg>
<p>This might be used in a call to the function <xfunction>serialize</xfunction>, for example:</p>
<eg>
serialize($input, {'method': 'xml',
'use-character-maps': character-map(xs:QName('jsp')) })
</eg>
<!--</example>-->
</fos:example>
</fos:examples>
</fos:function>

<fos:function name="system-property">
<fos:signatures>
Expand Down
42 changes: 35 additions & 7 deletions specifications/xslt-40/src/xslt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9651,7 +9651,7 @@ and <code>version="1.0"</code> otherwise.</p>
variables</xtermref> are defined by the <termref def="dt-variable-binding-element">variable binding elements</termref>
that are in scope for the containing element (see <specref ref="variables-and-parameters"/>).</p>
</item>
<item>
<!--<item>
<p>The <xtermref spec="XP40" ref="dt-context-value-static-type">context value
static type</xtermref> may be determined by an XSLT processor that
performs static type inferencing, using rules that are outside the scope of
Expand All @@ -9667,7 +9667,7 @@ and <code>version="1.0"</code> otherwise.</p>
<note><p>Note that some limited static type inferencing is
required in the case of a processor that performs streamability analysis:
see <specref ref="determining-static-type"/>.</p></note>
</item>
</item>-->
<item>
<p>The <xtermref spec="XP40" ref="dt-statically-known-function-definitions">statically known
function definitions</xtermref> are:</p>
Expand Down Expand Up @@ -9770,6 +9770,9 @@ and <code>version="1.0"</code> otherwise.</p>
<item>
<p>The set of named keys, used by the <function>key</function> function</p>
</item>
<item>
<p>The set of named character maps, used by the <function>character-map</function> function</p>
</item>

<item>
<p>The values of system properties, used by the
Expand All @@ -9780,14 +9783,14 @@ and <code>version="1.0"</code> otherwise.</p>
<function>element-available</function> function</p>
</item>
</ulist>
<p>A dynamic function call clears the first of these
<!--<p>A dynamic function call clears the first of these
components: this means that a dynamic call to the <function>key</function>
function will always raise a dynamic error (the key name is unknown). The values
of system properties and the set of available instructions, by contrast, reflect
the capabilities and configuration of the processor rather than values specific to
the stylesheet code itself; the result of a dynamic call to
<function>system-property</function> or <function>element-available</function>
will reflect the information available to the processor at evaluation time.</p>
will reflect the information available to the processor at evaluation time.</p>-->
<note>
<p>If these functions are called within a <termref def="dt-static-expression"/>, the results will reflect the capabilities and
configuration of the processor used to perform static analysis, while if they
Expand Down Expand Up @@ -38646,9 +38649,17 @@ return ($m?price - $m?discount)</eg>
</p>
<p>It is not an error if the same character map is referenced more than once, directly
or indirectly.</p>
<p>An <termref def="dt-output-definition">output definition</termref>, after recursive
expansion of character maps referenced via its <code>use-character-maps</code>
attribute, may contain several mappings for the same character. In this situation,

<p>For every <elcode>xsl:character-map</elcode> declaration in a <termref def="dt-package"/>,
other than one that is overridden by another of higher <termref def="dt-import-precedence"/>,
the static context of the package includes a named character map derived from the
<elcode>xsl:character-map</elcode> declaration. The name of the named character map is the
QName formed by expanding the value of the <code>name</code> attribute, and the content is
a map of type <code>map{xs:string, xs:string}</code> that maps characters (represented as
<code>xs:string</code> instances of length 1) to their replacement strings.</p>

<p>Recursive expansion of character maps using <code>use-character-maps</code>
attributes may produce several mappings for the same character. In this situation,
the last character mapping takes precedence. To establish the ordering, the following
rules are used:</p>
<ulist>
Expand Down Expand Up @@ -38752,6 +38763,23 @@ return ($m?price - $m?discount)</eg>
validation.</p>
</note>
</div2>
<div2 id="character-map-function">
<head>The <function>character-map</function> function</head>
<changes>
<change issue="1500">
The contents of a character map declared using <elcode>xsl:character-map</elcode> are now
available dynamically via a new <function>character-map</function> function.
</change>
</changes>
<p>The contents of a character map declared using <elcode>xsl:character-map</elcode> are
available dynamically via the <function>character-map</function> function.</p>

<div3 id="func-character-map">
<head><?function fn:character-map?></head>

</div3>
</div2>

<div2 id="disable-output-escaping">
<head>Disabling Output Escaping</head>
<p>Normally, when using the XML, HTML, or XHTML output method, the serializer will
Expand Down

0 comments on commit fae0aca

Please sign in to comment.