当我将 JavaScript 嵌入片段插入到 Mirage 主题内的容器末尾时,<div class="file-wrapper clearfix"></div>
由于item-view.xsl
某种原因<div id="ds-options-wrapper"></div>
,在.page-navigation.xsl
<div id="ds-body"></div>
我在其中编写了额外的 XSL <div class="file-wrapper clearfix"></div>
,仅当项目具有可用的 DOI 时才包含 JavaScript 嵌入mets.xml
。只要 DOI 可用,嵌入就会出现,但会导致<div id="ds-options-wrapper"></div>
成为 的子级<div id="ds-body"></div>
,而不是应有的兄弟级。只要没有嵌入,它就是默认 Mirage 模板中<div id="ds-options-wrapper"></div>
的兄弟并直接跟随。<div id="ds-body"></div>
为什么会这样?我想<div id="ds-options-wrapper"></div>
留下一个兄弟姐妹<div id="ds-body"></div>
下面是生成的 DOM 在有和没有嵌入的情况下的大致轮廓:
使用嵌入(伪代码)
<!-- id=" and class=" omitted -->
<div ds-content>
<div ds-body>
<div aspect_..._div_item-view>
<div item-summary-view-metadata>
</div>
<div file-list>
<div file-wrapper clearfix>
thumbnail-wrapper
file metadata
<!-- EMBED APPEARS HERE -->
<div embed> </div>
</div>
<div item-summary-view-metadata>
URI
Date
etc...
</div>
<h2> appears in... </h2>
<ul> referenceSet-list </ul>
</div>
</div>
<!-- ds-options-wrapper nested WITHIN ds-body for some reason -->
<div ds-options-wrapper>
.....
</div>
</div>
</div>
没有嵌入
<!-- id=" and class=" omitted -->
<div ds-content>
<div ds-body>
<div aspect_..._div_item-view>
<div item-summary-view-metadata>
</div>
<div file-list>
<div file-wrapper clearfix>
thumbnail-wrapper
file metadata
<!-- NO EMBED HERE -->
</div>
</div> <!-- file-list ends here ?? -->
<div item-summary-view-metadata>
URI
Date
etc...
</div>
<h2> appears in... </h2>
<ul referenceSet-list> </ul>
</div>
</div>
<!-- ds-options-wrapper nested OUTSIDE ds-body like normal -->
<div ds-options-wrapper>
.....
</div>
</div>
虽然这似乎并不重要,
这是我插入的代码item-view.xsl
<xsl:template match="mets:file">
<xsl:param name="context" select="."/>
<div class="file-wrapper clearfix">
<div class="thumbnail-wrapper">
....
</div>
<div class="file-metadata">
....
</div>
<!-- INSERTED CODE TO GENERATE JS EMBED HERE -->
<!-- Only output is either .... -->
<xsl:variable name="quoteChar">"</xsl:variable>
<xsl:choose>
<xsl:when test="//dim:field[@element='identifier'][@qualifier='doi']">
<xsl:variable name="doiVar" select="//dim:field[@element='identifier'][@qualifier='doi']"></xsl:variable>
<!-- HERE -->
<div data-badge-type='medium-donut' class='altmetric-embed' data-badge-details='right' data-doi='{$doiVar}'></div>
</xsl:when>
<xsl:otherwise>
<xsl:if test="contains(//dim:field[@element='identifier'][@qualifier='citation'],'doi')">
<xsl:variable name="parseThis" select="//dim:field[@element='identifier'][@qualifier='citation']"></xsl:variable>
<xsl:variable name="tokenized" select="str:split($parseThis, 'doi:')" />
<xsl:for-each select="$tokenized">
<xsl:variable name="curtoken" select="."/>
<xsl:if test="contains($curtoken, '10.') and contains($curtoken, '/')">
<xsl:variable name="newtext">
<xsl:call-template name="string-trim">
<xsl:with-param name="string" select="$curtoken" />
</xsl:call-template>
</xsl:variable>
<!-- OR HERE -->
<div data-badge-type='medium-donut' class='altmetric-embed' data-badge-details='right' data-doi='{$newtext}'></div>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!-- End Code -->
</div> <!-- end .file-wrapper clearfix-->
</xsl:template>
请注意,当嵌入存在时,出于某种原因<div class="file-list>
,也会封装包含 URI 和日期等的节点,但当不存在嵌入时,它不会这样做。
参数有什么作用context
?我看到它是从模板生成中调用的<div class="file-list">
。事实上,我根本不知道这个模板里面发生了什么:
<div class="file-list">
<xsl:choose>
<xsl:when test="...">
...
<!-- what goes on here? -->
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="mets:file">
<!-- what goes on here? -->
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</div>