|
12 | 12 | <xd:desc>
|
13 | 13 | <xd:p><xd:b>Created on:</xd:b> June 26, 2019</xd:p>
|
14 | 14 | <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> |
18 | 25 |
|
19 | 26 | </xd:desc>
|
20 | 27 | <xd:param name="configFile">A URI pointing to the config XML file that will be turned into the
|
21 | 28 | configuration XSLT.</xd:param>
|
22 | 29 | <xd:param name="buildReportFilename">A URI pointing to the staticSearch report file.</xd:param>
|
23 | 30 | <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 |
25 | 32 | for messages in the XSLT--useful primarily for debugging.</xd:param>
|
26 | 33 | </xd:doc>
|
27 | 34 |
|
|
44 | 51 | <xsl:variable name="verbose" as="xs:boolean" select="matches($ssVerbose,'^(t|true|y|yes|1)','i')" static="yes"/>
|
45 | 52 |
|
46 | 53 |
|
47 |
| - |
48 |
| - |
49 | 54 | <!--**************************************************************
|
50 | 55 | * *
|
51 | 56 | * NAMESPACE ALIAS *
|
|
325 | 330 | <xd:desc>
|
326 | 331 | <xd:p>Created on <xsl:value-of select="format-date(current-date(), '[Y0001]-[M01]-[D01]')"/> by an automated process.</xd:p>
|
327 | 332 | <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. |
331 | 338 | </xd:p>
|
332 | 339 | </xd:desc>
|
333 | 340 | </xd:doc>
|
|
344 | 351 |
|
345 | 352 | <!--Now create the dictionary XML files-->
|
346 | 353 | <xsl:call-template name="createDictionaryXML" exclude-result-prefixes="#all"/>
|
347 |
| - |
348 | 354 |
|
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> |
361 | 355 |
|
362 | 356 | <xsl:for-each select="$rules">
|
363 | 357 | <xso:template match="{@match}" priority="{$PRIORITY_THIRD}" mode="decorate">
|
|
368 | 362 | <xso:with-param name="value" select="{@weight}"/>
|
369 | 363 | <xso:with-param name="append">[<xsl:value-of select="local-name()"/>/@match=<xsl:value-of select="@match"/>]</xso:with-param>
|
370 | 364 | </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>--> |
382 | 365 | </xso:template>
|
383 | 366 | </xsl:for-each>
|
384 | 367 |
|
|
450 | 433 | </xsl:message>
|
451 | 434 |
|
452 | 435 | <!--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"> |
454 | 437 | <xso:param name="data" tunnel="yes" as="map(*)"/>
|
455 | 438 | <xso:variable name="weights" select="$data($KEY_WEIGHTS)" as="xs:integer*"/>
|
456 | 439 | <xso:variable name="ctxIds" select="$data($KEY_CONTEXT_IDS)" as="xs:string*"/>
|
|
459 | 442 | <xso:choose>
|
460 | 443 | <!--This is the root, so we must process it-->
|
461 | 444 | <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> |
462 | 457 | <xso:call-template name="hcmc:copy"/>
|
463 | 458 | </xso:when>
|
464 | 459 | <xso:when test="not(empty($weights)) and $weights[last()] = 0">
|
|
717 | 712 | </xsl:template>
|
718 | 713 |
|
719 | 714 |
|
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>--> |
852 | 715 |
|
853 | 716 | <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> |
856 | 720 | </xd:doc>
|
857 | 721 | <xsl:template name="createFilterLabels" exclude-result-prefixes="#all">
|
858 | 722 | <xso:variable name="filterLabels" as="element(hcmc:filter)*">
|
|
0 commit comments