]> Lady’s Gitweb - Shushe/blobdiff - lib/catalog2transform.xslt
Improve <书社:apply-attributes>, @书社:archived-as
[Shushe] / lib / catalog2transform.xslt
index 3cb8a2d6a540d24a032683267c2c451130bffc5a..2c555e32c189c0ade8b54990a7ed439910f40b46 100644 (file)
@@ -143,7 +143,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <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>
@@ -262,10 +262,11 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </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"/>
@@ -307,19 +308,57 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                        <xslt:for-each select="node()">
                                                <xslt:choose>
                                                        <xslt:when test="self::*">
-                                                               <xslt:variable name="component">
-                                                                       <xslt:choose>
-                                                                               <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
-                                                                                       <xslt:copy-of select="."/>
-                                                                               </xslt:when>
-                                                                               <xslt:otherwise>
-                                                                                       <xslt:call-template name="书社:wrap">
-                                                                                               <xslt:with-param name="nodes" select="."/>
-                                                                                       </xslt:call-template>
-                                                                               </xslt:otherwise>
-                                                                       </xslt:choose>
+                                                               <xslt:variable name="component-fragment">
+                                                                       <xslt:copy>
+                                                                               <xslt:choose>
+                                                                                       <xslt:when test="self::html:*">
+                                                                                               <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
+                                                                                               <xslt:attribute name="itemscope">itemscope</xslt:attribute>
+                                                                                               <xslt:attribute name="itemtype">
+                                                                                                       <xslt:for-each select="$existing-types/token">
+                                                                                                               <xslt:if test="position()!=1">
+                                                                                                                       <xslt:text>
+                                                                                                                               <text> </text>
+                                                                                                                       </xslt:text>
+                                                                                                               </xslt:if>
+                                                                                                               <xslt:value-of select="."/>
+                                                                                                       </xslt:for-each>
+                                                                                                       <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
+                                                                                                               <xslt:if test="$existing-types/token">
+                                                                                                                       <xslt:text>
+                                                                                                                               <text> </text>
+                                                                                                                       </xslt:text>
+                                                                                                               </xslt:if>
+                                                                                                               <xslt:text>
+                                                                                                                       <text>&书社;:document</text>
+                                                                                                               </xslt:text>
+                                                                                                       </xslt:if>
+                                                                                               </xslt:attribute>
+                                                                                               <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
+                                                                                       </xslt:when>
+                                                                                       <xslt:otherwise>
+                                                                                               <xslt:copy-of select="@*|node()"/>
+                                                                                       </xslt:otherwise>
+                                                                               </xslt:choose>
+                                                                       </xslt:copy>
+                                                               </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="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="$result-nodes"/>
+                                                                                               </xslt:call-template>
+                                                                                       </xslt:otherwise>
+                                                                               </xslt:choose>
+                                                                       </xslt:for-each>
                                                                </xslt:variable>
-                                                               <xslt:apply-templates select="exsl:node-set($component)/node()" mode="书社:apply"/>
+                                                               <xslt:apply-templates select="exsl:node-set($wrapped-component-fragment)/node()" mode="书社:apply"/>
                                                        </xslt:when>
                                                        <xslt:otherwise>
                                                                <xslt:apply-templates select="." mode="书社:apply"/>
@@ -346,6 +385,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </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)]"/>
@@ -363,22 +403,48 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                <xslt:copy>
                                                                        <xslt:choose>
                                                                                <xslt:when test="self::html:*">
+                                                                                       <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
                                                                                        <xslt:attribute name="itemscope">itemscope</xslt:attribute>
                                                                                        <xslt:attribute name="itemtype">
-                                                                                               <xslt:text>
-                                                                                                       <text>&书社;:embed</text>
-                                                                                               </xslt:text>
-                                                                                               <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
-                                                                                                       <xslt:text>
-                                                                                                               <text> </text>
-                                                                                                       </xslt:text>
+                                                                                               <xslt:for-each select="$existing-types/token[string()!='&书社;:document']">
+                                                                                                       <xslt:if test="position()!=1">
+                                                                                                               <xslt:text>
+                                                                                                                       <text> </text>
+                                                                                                               </xslt:text>
+                                                                                                       </xslt:if>
                                                                                                        <xslt:value-of select="."/>
                                                                                                </xslt:for-each>
+                                                                                               <xslt:if test="not($existing-types/token[string()='&书社;:embed'])">
+                                                                                                       <xslt:if test="$existing-types/token[string()!='&书社;:document']">
+                                                                                                               <xslt:text>
+                                                                                                                       <text> </text>
+                                                                                                               </xslt:text>
+                                                                                                       </xslt:if>
+                                                                                                       <xslt:text>
+                                                                                                               <text>&书社;:embed</text>
+                                                                                                       </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>
@@ -408,17 +474,27 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                        </xslt:if>
                                        <xslt:choose>
                                                <xslt:when test="self::html:*">
+                                                       <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
                                                        <xslt:attribute name="itemscope">itemscope</xslt:attribute>
                                                        <xslt:attribute name="itemtype">
-                                                               <xslt:text>
-                                                                       <text>&书社;:document</text>
-                                                               </xslt:text>
-                                                               <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
-                                                                       <xslt:text>
-                                                                               <text> </text>
-                                                                       </xslt:text>
+                                                               <xslt:for-each select="$existing-types/token">
+                                                                       <xslt:if test="position()!=1">
+                                                                               <xslt:text>
+                                                                                       <text> </text>
+                                                                               </xslt:text>
+                                                                       </xslt:if>
                                                                        <xslt:value-of select="."/>
                                                                </xslt:for-each>
+                                                               <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
+                                                                       <xslt:if test="$existing-types/token">
+                                                                               <xslt:text>
+                                                                                       <text> </text>
+                                                                               </xslt:text>
+                                                                       </xslt:if>
+                                                                       <xslt:text>
+                                                                               <text>&书社;:document</text>
+                                                                       </xslt:text>
+                                                               </xslt:if>
                                                        </xslt:attribute>
                                                        <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype') or namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
                                                </xslt:when>
This page took 0.281892 seconds and 4 git commands to generate.