|
<!-- This script converts records from the intermediate format
|
|
(output from the mapping-tool-generated XSLT) into
|
|
instances of the Asset schema. -->
|
|
<xsl:stylesheet version="2.0"
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
xmlns="http://www.wolterskluwer.com/ssr/asset"
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
|
xmlns:i2a="http://www.wolterskluwer.com/ns/i2a/internal-use"
|
|
exclude-result-prefixes="xs i2a">
|
|
|
|
<!-- Debug Parameter -->
|
|
<xsl:variable name="INFO" select="2" as="xs:integer"/>
|
|
<xsl:variable name="WARNING" select="1" as="xs:integer"/>
|
|
<xsl:variable name="ERROR" select="0" as="xs:integer"/>
|
|
<xsl:param name="debugLevel" select="$WARNING" as="xs:integer" />
|
|
|
|
<xsl:include href="element-config-rules.xsl"/>
|
|
<xsl:include href="assetInfo.xsl"/>
|
|
<xsl:include href="metadata.xsl"/>
|
|
<xsl:include href="contributor.xsl"/>
|
|
<xsl:include href="organization.xsl"/>
|
|
<xsl:include href="affiliation.xsl"/>
|
|
<xsl:include href="semanticMetadata.xsl"/>
|
|
<xsl:include href="sponsor.xsl"/>
|
|
<xsl:include href="taxonomyIdentifier.xsl"/>
|
|
<xsl:include href="valueList.xsl"/>
|
|
<xsl:include href="ofType.xsl"/>
|
|
<xsl:include href="textFormat.xsl"/>
|
|
<xsl:include href="date.xsl"/>
|
|
<xsl:include href="publicationHistory.xsl"/>
|
|
<xsl:include href="copyright.xsl"/>
|
|
<xsl:include href="util.xsl"/>
|
|
<xsl:include href="content-insertions.xsl"/>
|
|
<xsl:include href="citation.xsl"/>
|
|
<xsl:include href="question.xsl"/>
|
|
<xsl:include href="caption.xsl"/>
|
|
<xsl:include href="language.xsl"/>
|
|
<xsl:include href="full-text.xsl"/>
|
|
<xsl:include href="pagination.xsl"/>
|
|
<xsl:include href="table.xsl"/>
|
|
<xsl:include href="index.xsl"/>
|
|
<xsl:include href="toc.xsl"/>
|
|
|
|
<!--handles standards normalization for language & country-->
|
|
<xsl:include href="standardsNormalization.xsl"/>
|
|
|
|
<!-- Code for embedded resource sets -->
|
|
<xsl:include href="sets.xsl"/>
|
|
<xsl:include href="descriptor.xsl"/>
|
|
<xsl:include href="property.xsl"/>
|
|
<xsl:include href="presentation-data.xsl"/>
|
|
<xsl:include href="externalLink.xsl"/>
|
|
<xsl:include href="auxiliaryOfTypeRef.xsl"/>
|
|
<xsl:include href="childAssetMap.xsl"/>
|
|
|
|
<!-- If there are multiple records, place them inside an asset-collection -->
|
|
<xsl:template match="document-node()[count(records/record) gt 1]" priority="1">
|
|
<asset ofType="asset-collection" status="active">
|
|
<content ofType="asset-collection">
|
|
<contentList>
|
|
<xsl:for-each select="/records/record">
|
|
<xsl:call-template name="logInfo"><xsl:with-param name="message">Processing record <xsl:value-of select="position()"/> of <xsl:value-of select="last()"/></xsl:with-param></xsl:call-template>
|
|
<content ofType="asset">
|
|
<xsl:apply-templates select="."/>
|
|
</content>
|
|
</xsl:for-each>
|
|
</contentList>
|
|
</content>
|
|
</asset>
|
|
</xsl:template>
|
|
|
|
<!-- Otherwise, just output one asset (not in an asset-collection) -->
|
|
<xsl:template match="/">
|
|
<xsl:call-template name="logInfo"><xsl:with-param name="message">Processing record 1 of 1.</xsl:with-param></xsl:call-template>
|
|
<xsl:apply-templates select="/records/record"/>
|
|
</xsl:template>
|
|
|
|
<!-- Create one <asset> per <record> -->
|
|
<xsl:template match="/records/record">
|
|
<asset ofType="{assetInfo/i2a:ofType(.)}" status="{assetInfo/i2a:status(.)}">
|
|
<!-- everything (metadata and assetInfo), except descriptors, citations, indexes, glossary and childAssetMap-->
|
|
<!-- The main reason to enumerate the exceptions here is so that new top-level elements
|
|
will be processed and caught with the "NOT YET IMPLEMENTED" warning. -->
|
|
<xsl:variable name="childAssetMap-nodes" select=".//childAssetMap"/>
|
|
<xsl:sequence select="i2a:process(* except (l1d | cSet1 | questionSet | index | gSet1 | $childAssetMap-nodes))"/>
|
|
|
|
<xsl:variable name="language-nodes" select="i2a:language-nodes(.)"/>
|
|
<xsl:variable name="descriptor-nodes" select="l1d | .//descriptor"/>
|
|
<xsl:variable name="citation-nodes" select="cSet1"/>
|
|
<xsl:variable name="property-set-nodes" select="i2a:property-set-nodes(.)"/>
|
|
<xsl:variable name="presentation-set-nodes" select="i2a:presentation-set-nodes(.)"/>
|
|
<xsl:variable name="externalLink-set-nodes" select="i2a:externalLink-set-nodes(.)"/>
|
|
<xsl:variable name="auxiliaryOfType-set-nodes" select="i2a:auxiliaryOfType-set-nodes(.)"/>
|
|
<xsl:variable name="question-nodes" select="questionSet"/>
|
|
<xsl:variable name="index-nodes" select="index"/>
|
|
<xsl:variable name="glossary-nodes" select="gSet1"/>
|
|
|
|
<xsl:variable name="resource-nodes" select="$descriptor-nodes,
|
|
$language-nodes,
|
|
$citation-nodes,
|
|
$property-set-nodes,
|
|
$question-nodes,
|
|
$index-nodes,
|
|
$presentation-set-nodes,
|
|
$externalLink-set-nodes,
|
|
$auxiliaryOfType-set-nodes,
|
|
$glossary-nodes,
|
|
$childAssetMap-nodes"/>
|
|
|
|
<!-- languages, descriptors, citations, and properties -->
|
|
<xsl:if test="$resource-nodes">
|
|
<resourceList>
|
|
|
|
<!-- languages -->
|
|
<xsl:if test="$language-nodes">
|
|
<xsl:apply-templates mode="languages-list" select="."/>
|
|
</xsl:if>
|
|
|
|
<!-- descriptors -->
|
|
<xsl:if test="$descriptor-nodes">
|
|
<resource ofType="descriptors">
|
|
<descriptorSetList>
|
|
|
|
<!-- top-level asset descriptors -->
|
|
<xsl:sequence select="i2a:process(l1d)"/>
|
|
|
|
<!-- inline or inserted descriptors (everywhere else besides l1d) -->
|
|
<xsl:apply-templates mode="descriptor-set" select=".//*[not(ancestor-or-self::l1d)]
|
|
[descriptor]"/>
|
|
|
|
</descriptorSetList>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- citations -->
|
|
<xsl:if test="$citation-nodes">
|
|
<resource ofType="citations">
|
|
<xsl:sequence select="i2a:process($citation-nodes)"/>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- properties -->
|
|
<xsl:if test="$property-set-nodes">
|
|
<resource ofType="properties">
|
|
<propertySetList>
|
|
<xsl:apply-templates mode="property-set" select="i2a:property-set-nodes(.)"/>
|
|
</propertySetList>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- question sections -->
|
|
<xsl:if test="$question-nodes">
|
|
<resource ofType="questions">
|
|
<xsl:sequence select="i2a:process($question-nodes)"/>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- indexes -->
|
|
<xsl:if test="$index-nodes">
|
|
<resource ofType="index">
|
|
<xsl:sequence select="i2a:process($index-nodes)"/>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- glossary sections -->
|
|
<xsl:if test="$glossary-nodes">
|
|
<resource ofType="glossary">
|
|
<xsl:sequence select="i2a:process($glossary-nodes)"/>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- presentation data -->
|
|
<xsl:if test="$presentation-set-nodes">
|
|
<resource ofType="presentation-data">
|
|
<presentationDataSetList>
|
|
<xsl:apply-templates mode="presentation-set" select="i2a:presentation-set-nodes(.)"/>
|
|
</presentationDataSetList>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- externalLink sets -->
|
|
<xsl:if test="$externalLink-set-nodes">
|
|
<resource ofType="external-link">
|
|
<externalLinkSetList>
|
|
<xsl:apply-templates mode="externalLink-set" select="i2a:externalLink-set-nodes(.)"/>
|
|
</externalLinkSetList>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- auxiliaryOfType sets -->
|
|
<xsl:if test="$auxiliaryOfType-set-nodes">
|
|
<resource ofType="auxiliary-of-type">
|
|
<auxiliaryOfTypeSetList>
|
|
<xsl:apply-templates mode="auxiliaryOfType-set" select="i2a:auxiliaryOfType-set-nodes(.)"/>
|
|
</auxiliaryOfTypeSetList>
|
|
</resource>
|
|
</xsl:if>
|
|
|
|
<!-- childAssetMap sections -->
|
|
<xsl:if test="$childAssetMap-nodes">
|
|
<xsl:apply-templates mode="child-asset-map-list" select=".">
|
|
<xsl:with-param name="childAssetMap-nodes" select="$childAssetMap-nodes"/>
|
|
</xsl:apply-templates>
|
|
</xsl:if>
|
|
</resourceList>
|
|
</xsl:if>
|
|
</asset>
|
|
</xsl:template>
|
|
|
|
|
|
<!-- Convenience function for processing an element's primary content -->
|
|
<xsl:function name="i2a:process-content" as="item()*">
|
|
<xsl:param name="element" as="element()"/>
|
|
<xsl:sequence select="i2a:process(i2a:value-nodes($element))"/>
|
|
</xsl:function>
|
|
|
|
<!-- By default, don't use attributes for debug comments (when $DEBUG is enabled) -->
|
|
<xsl:function name="i2a:process" as="item()*">
|
|
<xsl:param name="nodes" as="node()*"/>
|
|
<xsl:sequence select="i2a:process($nodes, false())"/>
|
|
</xsl:function>
|
|
|
|
<!-- General function for processing a particular sequence of child nodes -->
|
|
<xsl:function name="i2a:process" as="item()*">
|
|
<xsl:param name="nodes" as="node()*"/>
|
|
<xsl:param name="use-attribute-for-debug-msg" as="xs:boolean"/>
|
|
|
|
<!-- Put element content into contiguous groups, in case a list wrapper is needed -->
|
|
<xsl:for-each-group select="$nodes" group-adjacent="i2a:name-of-nearest-element(.)">
|
|
<xsl:choose>
|
|
|
|
<!-- Yes, a list wrapper is needed -->
|
|
<xsl:when test="self::*/i2a:inside-list(.)">
|
|
<xsl:apply-templates mode="list-wrapper" select="."/>
|
|
</xsl:when>
|
|
|
|
<!-- When only one of the given element is expected and more are found;
|
|
complain and just process the last one -->
|
|
<xsl:when test="self::*/i2a:allow-only-one(.) and (current-group()/self::*)[2]">
|
|
<!-- Accommodated with unit test Log_Warnings.More_Than_One -->
|
|
<xsl:sequence select="i2a:WARNING(.,concat('More than one ',local-name(.),' was found. Ignoring all but the last.'))"/>
|
|
<xsl:apply-templates select="(current-group()/self::*)[last()]"/>
|
|
</xsl:when>
|
|
|
|
<!-- Should this element contain a valueList (instead of a list wrapper)? -->
|
|
<xsl:when test="self::*/i2a:has-valueList(.)">
|
|
<xsl:apply-templates select=".">
|
|
<xsl:with-param name="include-all-values" select="true()" tunnel="yes"/>
|
|
</xsl:apply-templates>
|
|
</xsl:when>
|
|
|
|
<!-- Otherwise, no list wrapper is needed and process all nodes in the group -->
|
|
<xsl:otherwise>
|
|
<xsl:apply-templates select="current-group()"/>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:for-each-group>
|
|
</xsl:function>
|
|
|
|
<!-- This is to ensure that text nodes don't cause contiguous
|
|
groups of elements to get split into separate groups
|
|
(because text nodes don't have a name) -->
|
|
<xsl:function name="i2a:name-of-nearest-element" as="xs:string">
|
|
<xsl:param name="node" as="node()"/>
|
|
<!-- If this is an element, then use its name; otherwise use the previous one's.
|
|
This ensures that any elements will always start the groups. -->
|
|
<xsl:variable name="element" select="$node/( self::*
|
|
, preceding-sibling::*[1]
|
|
)[1]"/>
|
|
|
|
<!-- Use the potentially renamed element name -->
|
|
<xsl:sequence select="string(
|
|
$element/( if (i2a:element-name(.))
|
|
then i2a:element-name(.)
|
|
else local-name(.)
|
|
)
|
|
)"/>
|
|
</xsl:function>
|
|
|
|
|
|
<!-- Wrap the contiguous elements in a list element -->
|
|
<xsl:template mode="list-wrapper" match="*">
|
|
<!-- Follow the xyzList element naming convention (by default) -->
|
|
<xsl:element name="{i2a:element-name(.)}List">
|
|
<!-- Does the list itself need any attributes? -->
|
|
<xsl:apply-templates mode="list-attributes" select="."/>
|
|
<!-- Process the element and all of its like-named siblings -->
|
|
<xsl:apply-templates select="current-group()"/>
|
|
<!-- Process generated-value templates, for parent -->
|
|
<xsl:apply-templates mode="generated-value" select=".."/>
|
|
</xsl:element>
|
|
</xsl:template>
|
|
|
|
<!--do not generate a list wrapper for citation metadata-->
|
|
<xsl:template mode="list-wrapper" match="metadata[@id = ..//inline-metadata-reference/@refId]">
|
|
<xsl:choose>
|
|
<xsl:when test="following-sibling::metadata[not(@id = ..//inline-metadata-reference/@refId)]">
|
|
<xsl:next-match/>
|
|
</xsl:when>
|
|
<xsl:otherwise/>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
|
|
<!-- By default, don't add any list attributes -->
|
|
<xsl:template mode="list-attributes" match="*"/>
|
|
|
|
|
|
<xsl:template match="*" mode="create-element">
|
|
<xsl:param name="name"/>
|
|
<!-- Create the corresponding element -->
|
|
<xsl:element name="{$name}">
|
|
<xsl:apply-templates select="." mode="process-element-body">
|
|
<xsl:with-param name="name" select="$name"/>
|
|
</xsl:apply-templates>
|
|
</xsl:element>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="publicationDate/date" mode="create-element">
|
|
<xsl:param name="name"/>
|
|
<!-- Dont Create Element -->
|
|
<xsl:apply-templates select="." mode="process-element-body">
|
|
<xsl:with-param name="name" select="$name"/>
|
|
</xsl:apply-templates>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="*" mode="process-element-body">
|
|
<xsl:param name="name"/>
|
|
<!-- for specific elements, create an updateId attribute -->
|
|
<xsl:if test="$name = ('representation','parentWkmrid','childAssetMap','pagination')">
|
|
<xsl:attribute name="updateId" select="i2a:genUpdateId($name,.)"/>
|
|
</xsl:if>
|
|
|
|
<!-- If present, copy the @id attribute through -->
|
|
<xsl:apply-templates mode="id-attribute" select="@id"/>
|
|
|
|
<!-- Translate any @refId attributes, as needed -->
|
|
<xsl:apply-templates mode="translate-refId" select="@refId"/>
|
|
|
|
<!-- Create the ofType and otherName attributes as applicable -->
|
|
<xsl:apply-templates mode="ofType-att" select="."/>
|
|
|
|
<!-- Output any additional attributes specific to the element -->
|
|
<xsl:apply-templates mode="additional-attributes" select="."/>
|
|
|
|
<!-- Create any attributes from normalization processing -->
|
|
<xsl:apply-templates mode="attribute-normalization" select="."/>
|
|
|
|
<!-- attribute elements must be processed first; identify which elements map to attributes -->
|
|
<xsl:variable name="attribute-elements" as="element()*">
|
|
<xsl:apply-templates mode="attribute-elements" select="."/>
|
|
</xsl:variable>
|
|
|
|
<!-- Process the attribute elements first -->
|
|
<xsl:sequence select="i2a:process($attribute-elements, true())"/>
|
|
|
|
<!-- Finally, generate the element content -->
|
|
<xsl:apply-templates mode="content" select=".">
|
|
<xsl:with-param name="content-nodes" select="node() except $attribute-elements"/>
|
|
</xsl:apply-templates>
|
|
|
|
</xsl:template>
|
|
|
|
|
|
<!-- Default rule for all elements -->
|
|
<xsl:template match="*" name="default-rule">
|
|
|
|
<!-- Get the mapped name, if available -->
|
|
<xsl:variable name="name" select="i2a:element-name(.)"/>
|
|
<xsl:choose>
|
|
|
|
<!-- If available, then create the corresponding element -->
|
|
<xsl:when test="$name">
|
|
|
|
<!-- Insert any content before the element -->
|
|
<xsl:apply-templates mode="before" select="."/>
|
|
|
|
<!-- Create element, or skip depending on need -->
|
|
<xsl:apply-templates mode="create-element" select=".">
|
|
<xsl:with-param name="name" select="$name"/>
|
|
</xsl:apply-templates>
|
|
|
|
<!-- Perform normalization after closing an element -->
|
|
<xsl:apply-templates mode="perform-normalization-after" select="."/>
|
|
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<!-- Any missing element/node should be logged here -->
|
|
<!--suppressing empty <full-text-content/> warning-->
|
|
<xsl:variable name="localName" select="local-name(.)"/>
|
|
<xsl:if test="not($localName = ('full-text-content', 'newTitle','indentLevel', 'startRefId','endRefId'))">
|
|
<xsl:call-template name="logWarning"><xsl:with-param name="message">Found Unknown intermediary node at XPATH: <xsl:value-of select="i2a:path(.)"/></xsl:with-param></xsl:call-template>
|
|
</xsl:if>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
|
|
<!-- By default, don't perform any normalization -->
|
|
<xsl:template mode="perform-normalization" match="*"/>
|
|
<xsl:template mode="perform-normalization-after" match="*"/>
|
|
|
|
<!-- By default, don't insert any content before the element -->
|
|
<xsl:template mode="before" match="*"/>
|
|
|
|
<!--suppress metadata/@id because its causing duplicates for citation/metadata-->
|
|
<xsl:template mode="id-attribute" match="metadata/@id[not(contains(.,'related-article') or contains(.,'sec-meta'))]"/>
|
|
|
|
<!-- By default, copy the @id attribute through -->
|
|
<xsl:template mode="id-attribute" match="@id">
|
|
<xsl:copy-of select="."/>
|
|
</xsl:template>
|
|
|
|
<!-- Look up what the refId attribute should be renamed to, if at all -->
|
|
<xsl:template mode="translate-refId" match="@refId">
|
|
<xsl:variable name="new-name" select="i2a:refId-becomes(..)"/>
|
|
<!-- if the result is an empty string, strip it out -->
|
|
<xsl:if test="$new-name">
|
|
<xsl:attribute name="{$new-name}" select="."/>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
|
|
<!--suppress @refId for sub-article & response content-->
|
|
<xsl:template mode="translate-refId" match="@refId[local-name(..) = ('content-ofType-response','content-ofType-sub-article')]"/>
|
|
|
|
<!-- The default element content consists of inserted nodes first, then the primary content -->
|
|
<xsl:template mode="content" match="*">
|
|
<xsl:param name="content-nodes" as="node()*"/>
|
|
|
|
<!-- First process any non-attribute inserted global elements (text-format, etc.) -->
|
|
<xsl:variable name="other-inserted-elements" as="element()*">
|
|
<xsl:apply-templates mode="other-inserted-elements" select="."/>
|
|
</xsl:variable>
|
|
<xsl:sequence select="i2a:process($other-inserted-elements)"/>
|
|
|
|
<!-- Perform any normalization steps needed in beginning -->
|
|
<xsl:apply-templates mode="perform-normalization" select="."/>
|
|
|
|
<!-- Finally, get the primary element content (process the rest) -->
|
|
<xsl:apply-templates mode="primary-content" select=".">
|
|
<xsl:with-param name="content-nodes" select="$content-nodes except $other-inserted-elements"
|
|
tunnel="yes"/>
|
|
</xsl:apply-templates>
|
|
</xsl:template>
|
|
|
|
<!-- Specify the default set of inserted global elements -->
|
|
<xsl:template mode="other-inserted-elements" match="*">
|
|
<!-- text-format, input-data, etc. -->
|
|
<xsl:sequence select="i2a:other-inserted-global-elements(.)"/>
|
|
</xsl:template>
|
|
|
|
<!-- Account for the possible scenario where insertions appear in subsequent values -->
|
|
<xsl:template mode="other-inserted-elements
|
|
attribute-elements" match="*[i2a:has-valueList(.)]" priority=".49">
|
|
<!-- if multiple values must be handled in the nested valueList -->
|
|
<xsl:param name="include-all-values" select="false()" tunnel="yes"/>
|
|
<!-- false when processing the first element (in which to merge fetched subsequent insertions) -->
|
|
<xsl:param name="fetching-subsequent-insertions" select="false()"/>
|
|
|
|
<!-- Start with the insertions for this element -->
|
|
<xsl:next-match/>
|
|
|
|
<!-- If multiple values must be represented in a child valueList
|
|
(because this element itself does not appear in a list in the result), then
|
|
we have no place in the result to put any subsequent insertions (or attributes)
|
|
(such as input-data for the second value), other than to merge them
|
|
into the one element. This loss of association between the content
|
|
insertion (or attribute) and the value to which it applies may or may
|
|
not be a problem. Since it could cause ambiguity in the data, we will
|
|
emit a warning if this happens. -->
|
|
<xsl:if test="i2a:has-valueList(.)
|
|
and $include-all-values
|
|
and not($fetching-subsequent-insertions)">
|
|
<!-- fetch any insertions for subsequent elements -->
|
|
<xsl:variable name="subsequent-insertions" as="item()*">
|
|
<xsl:apply-templates mode="#current" select="current-group()[position() gt 1][self::element()]">
|
|
<xsl:with-param name="fetching-subsequent-insertions" select="true()"/>
|
|
</xsl:apply-templates>
|
|
</xsl:variable>
|
|
|
|
<!-- If there are subsequent insertions -->
|
|
<xsl:if test="$subsequent-insertions">
|
|
<!-- Insert them here -->
|
|
<xsl:sequence select="$subsequent-insertions"/>
|
|
<!-- And emit a warning -->
|
|
<!-- Accommdated with unit test Log_Warnings.Subsequent_Insertions -->
|
|
<xsl:sequence select="i2a:WARNING(.,'Merging content insertions for multiple instances of this element; this may represent ambiguity in the result!')"/>
|
|
</xsl:if>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
|
|
<xsl:template mode="one-value-per-element" match="*">
|
|
<xsl:sequence select="false()"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template mode="one-value-per-element" match="spaceFlightMission | geneSymbol">
|
|
<xsl:sequence select="true()"/>
|
|
</xsl:template>
|
|
|
|
<!-- By default, group the content nodes using i2a:process() -->
|
|
<xsl:template mode="primary-content" match="*">
|
|
<xsl:param name="content-nodes" as="node()*" tunnel="yes"/>
|
|
<xsl:sequence select="i2a:process($content-nodes)"/>
|
|
</xsl:template>
|
|
|
|
<!-- For elements configured to contain a valueList as their content -->
|
|
<xsl:template mode="primary-content" match="*[i2a:has-valueList(.)]" priority=".49">
|
|
<!-- If the element is not already inside a list... -->
|
|
<xsl:param name="include-all-values" select="false()" tunnel="yes"/>
|
|
|
|
<xsl:variable name="oneValuePerElement" as="xs:boolean">
|
|
<xsl:apply-templates mode="one-value-per-element" select="."/>
|
|
</xsl:variable>
|
|
|
|
<xsl:choose>
|
|
<xsl:when test="$include-all-values and not($oneValuePerElement)">
|
|
<!-- ...then insert values for the entire group (could be just one) -->
|
|
<xsl:sequence select="i2a:valueList(current-group())"/>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<!-- Otherwise, just insert the value for the current element -->
|
|
<xsl:sequence select="i2a:valueList(.)"/>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
|
|
|
|
<!-- By default, don't add any additional attributes -->
|
|
<xsl:template mode="additional-attributes" match="*"/>
|
|
|
|
<!-- By default, handle attribute normalization for all elements -->
|
|
<xsl:template mode="attribute-normalization" match="*"/>
|
|
|
|
<!-- Specify the default set of global attribute elements -->
|
|
<xsl:template mode="attribute-elements" match="*">
|
|
|
|
<!-- First, the global ref attribute elements (e.g., lang & property) -->
|
|
<xsl:sequence select="i2a:global-attribute-elements(.)"/>
|
|
|
|
<!-- And then any additional, container-specific ones -->
|
|
<xsl:apply-templates mode="additional-attribute-elements" select="."/>
|
|
</xsl:template>
|
|
|
|
<!-- By default, don't add any additional attribute elements -->
|
|
<xsl:template mode="additional-attribute-elements" match="*"/>
|
|
|
|
|
|
<!-- Strip out whitespace-only text nodes -->
|
|
<xsl:template match="text()[not(normalize-space(.))]"/>
|
|
|
|
|
|
<!-- For the inserted DEBUG messages: -->
|
|
<!-- Show the element name -->
|
|
<!--
|
|
<xsl:template mode="debug-display" match="*">
|
|
<xsl:text><</xsl:text>
|
|
<xsl:value-of select="local-name()"/>
|
|
<xsl:text>></xsl:text>
|
|
<xsl:if test="position() ne last()">,</xsl:if>
|
|
</xsl:template>
|
|
-->
|
|
|
|
<!-- Indicate the presence of a text node -->
|
|
<!--
|
|
<xsl:template mode="debug-display" match="text()">
|
|
<xsl:text>#text('</xsl:text>
|
|
<xsl:value-of select="."/>
|
|
<xsl:text>')</xsl:text>
|
|
<xsl:if test="position() ne last()">,</xsl:if>
|
|
</xsl:template>
|
|
-->
|
|
|
|
<!-- Blow up if someone tries to process inline assets in I2A. -->
|
|
<xsl:template match="record//record">
|
|
<!-- Terminate if I2A executes on asset with inline-assets -->
|
|
<xsl:call-template name="logTerminate"><xsl:with-param name="message">You are attempting to run the I2A code on a file with inline assets. You must first split these into separate files before passing to the I2A code.</xsl:with-param></xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="logTerminate">
|
|
<xsl:param name="message" />
|
|
<xsl:call-template name="log">
|
|
<xsl:with-param name="message" select="$message" />
|
|
<xsl:with-param name="level" select="$ERROR" />
|
|
<xsl:with-param name="terminate" select="true()" />
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="logError">
|
|
<xsl:param name="message" />
|
|
<xsl:call-template name="log">
|
|
<xsl:with-param name="message" select="$message" />
|
|
<xsl:with-param name="level" select="$ERROR" />
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="logWarning">
|
|
<xsl:param name="message" />
|
|
<xsl:call-template name="log">
|
|
<xsl:with-param name="message" select="$message" />
|
|
<xsl:with-param name="level" select="$WARNING" />
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="logInfo">
|
|
<xsl:param name="message" />
|
|
<xsl:call-template name="log">
|
|
<xsl:with-param name="message" select="$message" />
|
|
<xsl:with-param name="level" select="$INFO" />
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="log">
|
|
<xsl:param name="message" />
|
|
<xsl:param name="level" />
|
|
<xsl:param name="terminate" select="false()" />
|
|
<xsl:variable name="logLabel">
|
|
<xsl:choose>
|
|
<xsl:when test="$level eq 2">
|
|
<xsl:value-of select="'INFO: '" />
|
|
</xsl:when>
|
|
<xsl:when test="$level eq 1">
|
|
<xsl:value-of select="'WARNING: '" />
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:value-of select="'ERROR: '" />
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:variable>
|
|
<xsl:if test="$level <= $debugLevel">
|
|
<xsl:variable name="output"
|
|
select="replace(normalize-space(translate(concat($logLabel,$message),'
', '?')),'([?])', '
')" />
|
|
<xsl:choose>
|
|
<xsl:when test="$terminate">
|
|
<xsl:message terminate="yes">
|
|
<xsl:value-of select="$output" />
|
|
</xsl:message>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:message terminate="no">
|
|
<xsl:value-of select="$output" />
|
|
</xsl:message>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="*" mode="report-unknown-nodes">
|
|
<xsl:call-template name="logWarning"><xsl:with-param name="message">Found Unknown Element from Custom Template: XPATH: <xsl:value-of select="i2a:path(.)"/></xsl:with-param></xsl:call-template>
|
|
</xsl:template>
|
|
|
|
|
|
</xsl:stylesheet>
|