-->
<transform
xmlns="http://www.w3.org/1999/XSL/Transform"
- xmlns:dct="http://purl.org/dc/terms/"
xmlns:exsl="http://exslt.org/common"
xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
extension-element-prefixes="exsl"
version="1.0"
>
- <variable name="builddir" select="//*[@rdf:about='about:shushe?builddir']/@nfo:fileUrl"/>
- <variable name="files" select="/rdf:RDF/nfo:LocalFileDataObject[not(nie:interpretedAs/nfo:Folder)]"/>
- <template name="书社:process-dependencies">
- <param name="processed"/>
- <param name="unprocessed"/>
- <variable name="queue">
- <copy-of select="exsl:node-set($unprocessed)/书社:dependency-root"/>
- <for-each select="exsl:node-set($unprocessed)/书社:dependency">
- <if test="not((exsl:node-set($processed)/书社:*|preceding-sibling::书社:*|following-sibling::书社:recursive-dependency)[string()=string(current())])">
- <copy-of select="."/>
- </if>
- </for-each>
- </variable>
- <variable name="old">
- <copy-of select="exsl:node-set($processed)/书社:dependency-root"/>
- <copy-of select="exsl:node-set($processed)/书社:recursive-dependency"/>
- <for-each select="exsl:node-set($unprocessed)/书社:recursive-dependency">
- <if test="not((exsl:node-set($processed)/书社:recursive-dependency|preceding-sibling::书社:recursive-dependency)[string()=string(current())])">
- <copy-of select="."/>
- </if>
- </for-each>
- <for-each select="exsl:node-set($processed)/书社:dependency">
- <if test="not(exsl:node-set($unprocessed)/书社:recursive-dependency[string()=string(current())])">
- <copy-of select="."/>
- </if>
- </for-each>
- <copy-of select="$queue"/>
- </variable>
- <variable name="new">
- <for-each select="exsl:node-set($queue)/书社:*">
- <for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument]">
- <variable name="parent" select="@rdf:about"/>
- <variable name="subdir">
+ <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
+ <variable name="files" select="//书社vocab:SourceFile|//书社vocab:IncludeFile"/>
+ <template name="书社:collect-dependency-paths">
+ <param name="path" select="/.."/>
+ <variable name="parent" select="string($path/*[last()])"/>
+ <variable name="children-fragment">
+ <for-each select="$files[@rdf:about=$parent and nie:interpretedAs/nfo:PlainTextDocument]">
+ <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
+ <for-each select="document($uri)//书社:link[@xlink:show='embed']">
+ <variable name="identifier" select="string(@xlink:href)"/>
+ <variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
+ <for-each select="$files/@rdf:about[string(.)=$identifier or $is-dir and starts-with(., $identifier)]">
+ <sort select="." data-type="text" lang="zxx" case-order="upper-first"/>
<choose>
- <when test="starts-with($parent, 'about:shushe?include=')">
- <text>/includes/</text>
- </when>
- <when test="starts-with($parent, 'about:shushe?source=')">
- <text>/sources/</text>
+ <when test="$path/*[string(.)=string(current())]">
+ <书社:recursive-dependency>
+ <value-of select="."/>
+ </书社:recursive-dependency>
</when>
+ <otherwise>
+ <书社:dependency>
+ <value-of select="."/>
+ </书社:dependency>
+ </otherwise>
</choose>
- </variable>
- <for-each select="document(concat($builddir, $subdir, @nfo:fileName), .)//书社:link[@xlink:show='embed']">
- <if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
- <书社:recursive-dependency>
- <value-of select="$parent"/>
- </书社:recursive-dependency>
- </if>
- <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
- <书社:dependency>
- <value-of select="@xlink:href"/>
- </书社:dependency>
- </if>
</for-each>
</for-each>
</for-each>
</variable>
+ <variable name="children" select="exsl:node-set($children-fragment)"/>
<choose>
- <when test="exsl:node-set($new)/书社:dependency">
- <call-template name="书社:process-dependencies">
- <with-param name="processed">
- <copy-of select="$old"/>
- </with-param>
- <with-param name="unprocessed">
- <copy-of select="$new"/>
- </with-param>
- </call-template>
+ <when test="$children/*">
+ <for-each select="$children/书社:recursive-dependency">
+ <书社:dependency-path>
+ <copy-of select="$path[string(.)=string(current())]/preceding-sibling::*"/>
+ <copy-of select="."/>
+ </书社:dependency-path>
+ </for-each>
+ <for-each select="$children/书社:dependency">
+ <variable name="path-fragment">
+ <copy-of select="$path"/>
+ <copy-of select="."/>
+ </variable>
+ <call-template name="书社:collect-dependency-paths">
+ <with-param name="path" select="exsl:node-set($path-fragment)"/>
+ </call-template>
+ </for-each>
</when>
<otherwise>
- <copy-of select="$old"/>
+ <书社:dependency-path>
+ <copy-of select="$path"/>
+ </书社:dependency-path>
</otherwise>
</choose>
</template>
- <template match="rdf:RDF/nfo:LocalFileDataObject[not(nie:interpretedAs/nfo:Folder or nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
+ <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
<copy>
- <apply-templates select="@*|node()"/>
- <if test="starts-with(@rdf:about, 'about:shushe?source=')">
- <dct:hasFormat>
- <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{substring-after(@rdf:about, 'about:shushe?source=')}"/>
- </dct:hasFormat>
- </if>
+ <apply-templates select="@*"/>
+ <attribute name="书社vocab:destination">
+ <value-of select="@书社vocab:path"/>
+ </attribute>
+ <apply-templates select="node()"/>
</copy>
</template>
- <template match="rdf:RDF/nfo:LocalFileDataObject[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
- <variable name="parsed" select="document(concat($builddir, '/sources/', @nfo:fileName), .)"/>
+ <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
+ <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
<variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
<variable name="destination">
<choose>
- <when test="not(starts-with(@rdf:about, 'about:shushe?source='))"/>
<when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
<value-of select="$parsed/*/@书社:destination"/>
</when>
<otherwise>
- <value-of select="substring-after(@rdf:about, 'about:shushe?source=')"/>
+ <value-of select="@书社vocab:path"/>
</otherwise>
</choose>
</variable>
<variable name="dependencies-fragment">
<apply-templates select="." mode="书社:dependencies"/>
</variable>
- <variable name="dependencies" select="exsl:node-set($dependencies)"/>
+ <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
+ <copy>
+ <apply-templates select="@*"/>
+ <attribute name="书社vocab:destination">
+ <value-of select="$destination"/>
+ </attribute>
+ <apply-templates select="node()"/>
+ <for-each select="$dependencies/书社:dependency">
+ <书社vocab:hasDependencyOn rdf:resource="{.}"/>
+ </for-each>
+ <for-each select="$dependencies/书社:recursive-dependency">
+ <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
+ </for-each>
+ </copy>
+ </template>
+ <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
+ <variable name="dependencies-fragment">
+ <apply-templates select="." mode="书社:dependencies"/>
+ </variable>
+ <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
<copy>
<apply-templates select="@*|node()"/>
<for-each select="$dependencies/书社:dependency">
<for-each select="$dependencies/书社:recursive-dependency">
<书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
</for-each>
- <if test="$destination!=''">
- <dct:hasFormat>
- <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{$destination}">
- </nfo:LocalFileDataObject>
- </dct:hasFormat>
- </if>
</copy>
</template>
+ <template match="/">
+ <variable name="result-fragment">
+ <apply-templates/>
+ </variable>
+ <variable name="result" select="exsl:node-set($result-fragment)"/>
+ <copy-of select="$result/*"/>
+ <exsl:document href="dependencies" method="text" encoding="UTF-8">
+ <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
+ <value-of select="@rdf:about"/>
+ <text>
</text>
+ <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
+ <text>	</text>
+ <text>-</text>
+ <value-of select="."/>
+ <text>
</text>
+ </for-each>
+ <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
+ <text>	</text>
+ <value-of select="."/>
+ <text>
</text>
+ </for-each>
+ </for-each>
+ </exsl:document>
+ <exsl:document href="destinations" method="text" encoding="UTF-8">
+ <for-each select="$result//书社vocab:SourceFile">
+ <value-of select="@rdf:about"/>
+ <text>|</text>
+ <value-of select="@书社vocab:destination"/>
+ <text>
</text>
+ </for-each>
+ </exsl:document>
+ </template>
<template match="@*|node()">
<copy>
<apply-templates select="@*|node()"/>
</copy>
</template>
- <template match="nfo:LocalFileDataObject" mode="书社:dependencies">
+ <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
<if test="nie:interpretedAs/nfo:PlainTextDocument">
- <call-template name="书社:process-dependencies">
- <with-param name="unprocessed">
- <书社:dependency-root>
- <value-of select="@rdf:about"/>
- </书社:dependency-root>
- </with-param>
- </call-template>
+ <variable name="path-fragment">
+ <书社:dependency-root>
+ <value-of select="@rdf:about"/>
+ </书社:dependency-root>
+ </variable>
+ <variable name="paths-fragment">
+ <call-template name="书社:collect-dependency-paths">
+ <with-param name="path" select="exsl:node-set($path-fragment)"/>
+ </call-template>
+ </variable>
+ <for-each select="exsl:node-set($paths-fragment)/*/*[not(self::书社:dependency-root)]">
+ <if test="not(preceding::*[string(.)=string(current())])">
+ <copy-of select="."/>
+ </if>
+ </for-each>
</if>
</template>
+ <output method="xml" encoding="UTF-8"/>
</transform>