Skip to content

Commit 4abbab7

Browse files
committed
Small fixes and lots of documentation
1 parent 02e6e69 commit 4abbab7

File tree

2 files changed

+109
-263
lines changed

2 files changed

+109
-263
lines changed

xsl/create_config_xsl.xsl

Lines changed: 32 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212
<xd:desc>
1313
<xd:p><xd:b>Created on:</xd:b> June 26, 2019</xd:p>
1414
<xd:p><xd:b>Authors:</xd:b> Joey Takeda and Martin Holmes</xd:p>
15-
<xd:p>This transformation converts the configuration file (config.xml) into
16-
an XSLT stylesheet, which is imported into the main tokenization stylesheet
17-
to allow for various configuration options. <!--WRITE MORE HERE ONCE WRITTEN--></xd:p>
15+
<xd:p>This transformation converts the user-supplied configuration file (config.xml) into
16+
an XSLT stylesheet that can be imported throughout the process. In particular,
17+
the generated configuration contains:</xd:p>
18+
<xd:ul>
19+
<xd:li>Global variables and parameters that correspond to (or calculated from)
20+
configuration options</xd:li>
21+
<xd:li>Templates (derived from rules) to customize the tokenization process;
22+
see <xd:a href="tokenize.xsl">tokenize.xsl</xd:a> for full documentation
23+
on the tokenization process.</xd:li>
24+
</xd:ul>
1825

1926
</xd:desc>
2027
<xd:param name="configFile">A URI pointing to the config XML file that will be turned into the
2128
configuration XSLT.</xd:param>
2229
<xd:param name="buildReportFilename">A URI pointing to the staticSearch report file.</xd:param>
2330
<xd:param name="ssBaseDir">The basedir for staticSearch</xd:param>
24-
<xd:param name="verbose">Flag passed from ant that describes the user set verbosity setting
31+
<xd:param name="ssVerbose">Flag passed from ant that describes the user set verbosity setting
2532
for messages in the XSLT--useful primarily for debugging.</xd:param>
2633
</xd:doc>
2734

@@ -44,8 +51,6 @@
4451
<xsl:variable name="verbose" as="xs:boolean" select="matches($ssVerbose,'^(t|true|y|yes|1)','i')" static="yes"/>
4552

4653

47-
48-
4954
<!--**************************************************************
5055
* *
5156
* NAMESPACE ALIAS *
@@ -325,9 +330,11 @@
325330
<xd:desc>
326331
<xd:p>Created on <xsl:value-of select="format-date(current-date(), '[Y0001]-[M01]-[D01]')"/> by an automated process.</xd:p>
327332
<xd:p><xd:b>Authors:</xd:b> Joey Takeda and Martin Holmes</xd:p>
328-
<xd:p>This is the temporary stylesheet derived from <xsl:value-of select="$configUri"/> and generated by <xsl:value-of select="base-uri()"/>.
329-
See <xd:a href="create_config_xsl.xsl">create_config_xsl.xsl</xd:a> (or https://github.com/projectEndings/staticSearch/blob/master/xsl/create_config_xsl.xsl)
330-
for further information on how this document is created and the purpose it serves for the static search codebase.
333+
<xd:p>This is the temporary stylesheet derived from <xsl:value-of select="$configUri"/> and generated by
334+
<xsl:value-of select="base-uri()"/>. See <xd:a href="create_config_xsl.xsl">create_config_xsl.xsl</xd:a>
335+
(or https://github.com/projectEndings/staticSearch/blob/master/xsl/create_config_xsl.xsl)
336+
for further information on how this document is created and the purpose it serves for the
337+
staticSearch codebase.
331338
</xd:p>
332339
</xd:desc>
333340
</xd:doc>
@@ -344,20 +351,7 @@
344351

345352
<!--Now create the dictionary XML files-->
346353
<xsl:call-template name="createDictionaryXML" exclude-result-prefixes="#all"/>
347-
348354

349-
<xso:template match="*" priority="{$PRIORITY_FIRST}" mode="decorate">
350-
<xso:next-match>
351-
<xso:with-param name="data" tunnel="yes" as="map(*)">
352-
<xso:map>
353-
<xso:map-entry key="$KEY_WEIGHTS" select="()"/>
354-
<xso:map-entry key="$KEY_CONTEXTS" select="()"/>
355-
<xso:map-entry key="$KEY_CONTEXT_IDS" select="()"/>
356-
<xso:map-entry key="$KEY_EXCLUDES" select="()"/>
357-
</xso:map>
358-
</xso:with-param>
359-
</xso:next-match>
360-
</xso:template>
361355

362356
<xsl:for-each select="$rules">
363357
<xso:template match="{@match}" priority="{$PRIORITY_THIRD}" mode="decorate">
@@ -368,17 +362,6 @@
368362
<xso:with-param name="value" select="{@weight}"/>
369363
<xso:with-param name="append">[<xsl:value-of select="local-name()"/>/@match=<xsl:value-of select="@match"/>]</xso:with-param>
370364
</xso:call-template>
371-
<!--FORMER WAY OF DOING THIS: KEEPING HERE BUT SHOULD REMOVE-->
372-
<!--<xso:variable name="oldVals" select="map:get($data,$KEY_WEIGHTS)" as="xs:integer*"/>
373-
<xso:variable name="thisWeight" select="{@weight}" as="xs:integer"/>
374-
<xso:variable name="newVals" select="($oldVals, $thisWeight)" as="xs:integer+"/>
375-
<xsl:call-template name="printTemplateDebug">
376-
<xsl:with-param name="key" select="$KEY_WEIGHTS"/>
377-
</xsl:call-template>
378-
<xso:next-match>
379-
<xso:with-param name="data" tunnel="yes" as="map(*)"
380-
select="map:put($data, $KEY_WEIGHTS, $newVals)"/>
381-
</xso:next-match>-->
382365
</xso:template>
383366
</xsl:for-each>
384367

@@ -450,7 +433,7 @@
450433
</xsl:message>
451434

452435
<!--Now, finally, the last rule -->
453-
<xso:template match="*" name="last" priority="{$PRIORITY_LAST}" mode="decorate">
436+
<xso:template match="*" name="hcmc:last" priority="{$PRIORITY_LAST}" mode="decorate">
454437
<xso:param name="data" tunnel="yes" as="map(*)"/>
455438
<xso:variable name="weights" select="$data($KEY_WEIGHTS)" as="xs:integer*"/>
456439
<xso:variable name="ctxIds" select="$data($KEY_CONTEXT_IDS)" as="xs:string*"/>
@@ -459,6 +442,18 @@
459442
<xso:choose>
460443
<!--This is the root, so we must process it-->
461444
<xso:when test="not(ancestor::*)">
445+
<xso:if test="not(empty($weights)) and $weights[last()] = 0">
446+
<xso:message terminate="yes">
447+
*********************************************
448+
ERROR: You have specified a weight of 0 for
449+
the root <xso:value-of select="local-name()"/> element,
450+
which would create an empty output file and generate an error during
451+
tokenization.
452+
453+
Did you mean to use an exclude instead?
454+
*********************************************
455+
</xso:message>
456+
</xso:if>
462457
<xso:call-template name="hcmc:copy"/>
463458
</xso:when>
464459
<xso:when test="not(empty($weights)) and $weights[last()] = 0">
@@ -717,142 +712,11 @@
717712
</xsl:template>
718713

719714

720-
<!-- <xd:doc>
721-
<xd:desc>
722-
<xd:p>The <xd:ref name="createRetainRules" type="template">createRetainRules</xd:ref> template
723-
creates an XSL identity template for the xpaths specified in the configuration file that have
724-
either a weight greater than 0 OR want to be retained as a context item for the kwic.</xd:p>
725-
</xd:desc>
726-
</xd:doc>
727-
<xsl:template name="createRetainRules" exclude-result-prefixes="#all">
728-
<xso:template match="{string-join($retainRules/@match,' | ')}" priority="1" mode="clean">
729-
<xso:if test="$verbose">
730-
<xso:message>Template #clean: retaining <xso:value-of select="local-name(.)"/></xso:message>
731-
</xso:if>
732-
<xso:copy>
733-
<xso:apply-templates select="@*|node()" mode="#current"/>
734-
</xso:copy>
735-
</xso:template>
736-
</xsl:template>-->
737-
738-
<!--
739-
<xd:doc>
740-
<xd:desc>
741-
<xd:p>The <xd:ref name="createDeleteRules" type="template">createDeleteRules</xd:ref> template
742-
creates an XSL identity template for the xpaths specified in the configuration file that have
743-
a weight of 0, which signals that these elements should be deleted from the tokenization process.
744-
These are usually elements that have text content that shouldn't be analyzed (for instance, footer
745-
text that appears in every document or navigation items).</xd:p>
746-
</xd:desc>
747-
</xd:doc>
748-
<xsl:template name="createDeleteRules" exclude-result-prefixes="#all">
749-
<xso:template match="{string-join($deleteRules/@match,' | ')}" priority="1" mode="clean">
750-
<xso:if test="$verbose">
751-
<xso:message>Template #clean: Deleting <xso:value-of select="local-name(.)"/></xso:message>
752-
</xso:if>
753-
<xso:if test="local-name() = 'html'">
754-
<xso:message terminate="yes">
755-
*********************************************
756-
ERROR: You have specified a weight of 0 for
757-
an html element, which will create an empty
758-
output file and generate an error during
759-
tokenization.
760-
*********************************************
761-
</xso:message>
762-
</xso:if>
763-
</xso:template>
764-
</xsl:template>-->
765-
766-
767-
<xd:doc>
768-
<xd:desc>
769-
<xd:p>The <xd:ref name="createExcludeRules" type="template">createDeleteRules</xd:ref> template
770-
creates an XSL identity template for the xpaths specified in the configuration file that have been excluded from the tokenization
771-
process.</xd:p>
772-
</xd:desc>
773-
</xd:doc>
774-
<!-- <xsl:template name="createExcludeRules" exclude-result-prefixes="#all">
775-
<xso:template match="{string-join($excludeRules/@match, ' | ')}" priority="1" mode="exclude">
776-
<xso:if test="$verbose">
777-
<xso:message>Template #exclude: Adding @ss-excld flag to <xso:value-of select="local-name(.)"/></xso:message>
778-
</xso:if>
779-
<xso:copy>
780-
<xso:attribute name="ss-excld" select="'true'"/>
781-
<xso:apply-templates select="@*|node()" mode="#current"/>
782-
</xso:copy>
783-
</xso:template>
784-
</xsl:template>-->
785-
786-
<xd:doc>
787-
<xd:desc>
788-
<xd:p>The <xd:ref name="createContextRules" type="template">createContextRules</xd:ref> template
789-
creates an XSL identity template for the xpaths specified in the configuration file that are
790-
specified as context nodes for the kwic. It also creates the map of context ids/labels,
791-
if they are specified in the config, for creating the "Search in" configuration.</xd:p>
792-
</xd:desc>
793-
</xd:doc>
794-
<xsl:template name="createContextRules" exclude-result-prefixes="#all">
795-
796-
797-
798-
<!-- <xsl:if test="not(empty($contexts))">
799-
<xso:template match="{string-join($contexts/@match,' | ')}" priority="1" mode="contextualize">
800-
<xso:if test="$verbose">
801-
<xso:message>Template #contextualize: Adding @ss-ctx flag to <xso:value-of select="local-name(.)"/></xso:message>
802-
</xso:if>
803-
<xso:copy>
804-
<xso:apply-templates select="@*" mode="#current"/>
805-
<xsl:for-each select="$contexts">
806-
<xsl:variable name="thisCtx" select="@context"/>
807-
<xsl:variable name="thisMatchPtn" select="@match"/>
808-
<xsl:variable name="thisLabel" select="@label"/>
809-
<xsl:for-each select="tokenize($thisMatchPtn,'\s*\|\s*')">
810-
<xso:if test="self::{.}">
811-
<xso:attribute name="ss-ctx" select="{hcmc:quoteString(hcmc:stringToBoolean($thisCtx))}"/>
812-
<!-\-If the context has a label, then add its corresponding context id value-\->
813-
<xsl:if test="exists($thisLabel)">
814-
<xsl:variable name="contextId"
815-
select="$contextMap(normalize-space($thisLabel))"
816-
as="xs:string"/>
817-
<xso:attribute name="ss-ctx-id" select="{hcmc:quoteString($contextId)}"/>
818-
</xsl:if>
819-
</xso:if>
820-
</xsl:for-each>
821-
822-
</xsl:for-each>
823-
<xso:apply-templates select="node()" mode="#current"/>
824-
</xso:copy>
825-
</xso:template>
826-
</xsl:if>-->
827-
</xsl:template>
828-
<!--
829-
<xd:doc>
830-
<xd:desc>
831-
<xd:p>The <xd:ref name="createWeightingRules" type="template">createWeightingRules</xd:ref> template
832-
creates an XSL identity template for the xpaths specified in the configuration file that have
833-
some non-0 weight specified.</xd:p>
834-
</xd:desc>
835-
</xd:doc>
836-
<xsl:template name="createWeightingRules" exclude-result-prefixes="#all">
837-
<xso:template match="{string-join($weightedRules/@match,' | ')}" priority="1" mode="weigh">
838-
<xso:if test="$verbose">
839-
<xso:message>Template #weigh: Adding @data-weight to <xso:value-of select="local-name(.)"/></xso:message>
840-
</xso:if>
841-
<xso:copy>
842-
<xso:apply-templates select="@*" mode="#current"/>
843-
<xsl:for-each select="$weightedRules[xs:integer(@weight) gt 1]">
844-
<xso:if test="self::{@match}">
845-
<xso:attribute name="ss-wt" select="{@weight}"/>
846-
</xso:if>
847-
</xsl:for-each>
848-
<xso:apply-templates select="node()" mode="#current"/>
849-
</xso:copy>
850-
</xso:template>
851-
</xsl:template>-->
852715

853716
<xd:doc>
854-
<xd:desc>The <xd:ref name="createFilterLabels" type="template">createFilterLabels</xd:ref> template creates a copy of the original filter data in a variable; there's no real reason to process
855-
it in any special way.</xd:desc>
717+
<xd:desc>The <xd:ref name="createFilterLabels" type="template">createFilterLabels</xd:ref> template creates
718+
a copy of the original filter data in a variable; there's no real reason to process
719+
it in any special way.</xd:desc>
856720
</xd:doc>
857721
<xsl:template name="createFilterLabels" exclude-result-prefixes="#all">
858722
<xso:variable name="filterLabels" as="element(hcmc:filter)*">

0 commit comments

Comments
 (0)