<xslt:choose>
<xslt:when test="@namespace-uri='&xml;'"/>
<xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
- <xslt:when test="@namespace-uri='&书社;' and @local-name='archived-as' and not($context-nodes/ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)][1][self::书社:archive])"/>
+ <xslt:when test="@namespace-uri='&书社;' and @local-name='archived-as' and $context-nodes/ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)][position()=1 and not(self::书社:archive)]"/>
<xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
<xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
<xslt:otherwise>
</html:html>
</xslt:template>
<xslt:template match="/" priority="1">
- <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+ <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+ <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
<xslt:variable name="root-with-attributes">
<xslt:choose>
- <xslt:when test="not($result-nodes/self::html:*) or $result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $result-nodes/@书社:disable-output-wrapping or $书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
+ <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-nodes/@书社:disable-output-wrapping or $书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
<xslt:call-template name="书社:apply-attributes">
<xslt:with-param name="and-version" select="true()"/>
<xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
</xslt:variable>
<xslt:variable name="wrapped-component-fragment">
<xslt:for-each select="exsl:node-set($component-fragment)/*">
+ <xslt:variable name="result-nodes" select="self::*[not(self::书社:apply-attributes-to-root)]|self::书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+ <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
<xslt:choose>
- <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
+ <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-nodes/@书社:disable-output-wrapping">
<xslt:copy-of select="."/>
</xslt:when>
<xslt:otherwise>
<xslt:call-template name="书社:wrap">
- <xslt:with-param name="nodes" select="."/>
+ <xslt:with-param name="nodes" select="$result-nodes"/>
</xslt:call-template>
</xslt:otherwise>
</xslt:choose>
</xslt:copy>
</xslt:template>
<xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
+ <xslt:variable name="link" select="."/>
<xslt:variable name="identifier" select="string(@xlink:href)"/>
<xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
<xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
</xslt:text>
</xslt:if>
</xslt:attribute>
- <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
+ <xslt:choose>
+ <xslt:when test="$link/@书社:archived-as">
+ <xslt:copy-of select="$link/@书社:archived-as"/>
+ </xslt:when>
+ <xslt:when test="@书社:archived-as">
+ <xslt:copy-of select="@书社:archived-as"/>
+ </xslt:when>
+ </xslt:choose>
+ <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
</xslt:when>
<xslt:otherwise>
- <xslt:copy-of select="@*|node()"/>
+ <xslt:choose>
+ <xslt:when test="self::* and $link/@书社:archived-as">
+ <xslt:copy-of select="$link/@书社:archived-as"/>
+ </xslt:when>
+ <xslt:when test="@书社:archived-as">
+ <xslt:copy-of select="@书社:archived-as"/>
+ </xslt:when>
+ </xslt:choose>
+ <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
</xslt:otherwise>
</xslt:choose>
</xslt:copy>