diff --git a/src/xproc/publish.xpl b/src/xproc/publish.xpl index 23fe8484d36d96857f369fdb93383ce7e5a0f9b7..4ddf9fa88128f3bde890d8e0df7e6fe19daf6d9a 100644 --- a/src/xproc/publish.xpl +++ b/src/xproc/publish.xpl @@ -2,41 +2,58 @@ xmlns:p="http://www.w3.org/ns/xproc"> <p:input port="source" primary="true" sequence="false"/> - <p:output port="result" primary="true" sequence="false"/> - - <p:option name="objectId" required="true"/> - - <p:serialization port="result" indent="true"/> - - <p:validate-with-schematron name="validate-kitodo"> - <p:input port="source"> - <p:pipe step="main" port="source"/> - </p:input> - <p:input port="schema"> - <p:document href="../schema/kitodo.sch"/> - </p:input> - <p:input port="parameters"> - <p:empty/> - </p:input> - </p:validate-with-schematron> - - <p:xslt name="normalize"> - <p:with-param name="objectId" select="$objectId"/> - <p:input port="source"> - <p:pipe step="validate-kitodo" port="result"/> - </p:input> - <p:input port="stylesheet"> - <p:document href="../xslt/mets.xsl"/> - </p:input> - </p:xslt> - - <p:validate-with-xml-schema assert-valid="true"> - <p:input port="source"> - <p:pipe step="normalize" port="result"/> - </p:input> - <p:input port="schema"> - <p:document href="../schema/mets.xsd"/> - </p:input> - </p:validate-with-xml-schema> + + <p:option name="objectId" required="true"/> + <p:option name="targetUri" required="true"/> + + <p:choose> + <p:when test="doc-available(resolve-uri($targetUri))"> + <p:error code="TargetFileExists"> + <p:input port="source"> + <p:empty/> + </p:input> + </p:error> + <p:sink/> + </p:when> + <p:otherwise> + + <p:validate-with-schematron name="validate-kitodo"> + <p:input port="source"> + <p:pipe step="main" port="source"/> + </p:input> + <p:input port="schema"> + <p:document href="../schema/kitodo.sch"/> + </p:input> + <p:input port="parameters"> + <p:empty/> + </p:input> + </p:validate-with-schematron> + + <p:xslt name="normalize"> + <p:with-param name="objectId" select="$objectId"/> + <p:input port="source"> + <p:pipe step="validate-kitodo" port="result"/> + </p:input> + <p:input port="stylesheet"> + <p:document href="../xslt/mets.xsl"/> + </p:input> + </p:xslt> + + <p:validate-with-xml-schema assert-valid="true"> + <p:input port="source"> + <p:pipe step="normalize" port="result"/> + </p:input> + <p:input port="schema"> + <p:document href="../schema/mets.xsd"/> + </p:input> + </p:validate-with-xml-schema> + + <p:store> + <p:with-option name="href" select="$targetUri"/> + </p:store> + + </p:otherwise> + + </p:choose> </p:declare-step>