Project

Profile

Help

Bug #6161 ยป delete-obsolete-trains.xslt

Johan Gheys, 2023-08-09 09:17

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:local="urn:local-functions"
xmlns:shared="urn:shared-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:import href="/shared/shared-functions.xslt"/>
<xsl:param name="old-file" as="xs:string"/>
<xsl:param name="new-file" as="xs:string"/>
<xsl:param name="working-folder" as="xs:string"/>
<xsl:param name="output-folder" as="xs:string"/>
<xsl:variable name="newXML" select="shared:open-file($new-file)"/>
<xsl:key name="with-functionalKey" match="*" use="@functionalKey"/>

<xsl:template name="xsl:initial-template" match="/">
<xsl:variable name="oldXML" select="shared:open-file($old-file)"/>
<xsl:apply-templates select="$oldXML/*"/>
</xsl:template>

<xsl:template match="train">
<xsl:variable name="newTrain" select="local:getNewTrain(.)"/>
<xsl:if test="empty($newTrain)">
<xsl:variable name="fileName" select="@href"/>
<xsl:variable name="file" select="shared:path-to-uri($output-folder, $fileName)"/>
<xsl:result-document href="{$file}" method="xml"/>
<xsl:sequence select="shared:delete(concat($working-folder, $fileName))"/>
</xsl:if>
</xsl:template>

<xsl:function name="local:getNewTrain" as="element(train)?">
<xsl:param name="element" as="element(train)"/>
<xsl:for-each select="$element">
<xsl:sequence select="key('with-functionalKey', @functionalKey, $newXML)"/>
</xsl:for-each>
</xsl:function>

</xsl:stylesheet>
    (1-1/1)