--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:wdef="https://purl.choffet.net/wdef"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<!-- replace_id.xslt - Replace wdef id value while keeping references in sync.
+ Copyright (C) 2020, 2021, 2022 Pierre Choffet
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of version 3 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+ <xsl:output method="xml" encoding="utf-8" />
+
+ <xsl:param name="old-id" />
+ <xsl:param name="new-id" />
+
+ <xsl:template match="@*">
+ <xsl:copy>
+ <xsl:apply-templates select="@*" />
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="node()">
+ <xsl:copy>
+ <xsl:choose>
+ <xsl:when test="not(@wdef:id) or @wdef:id != $old-id">
+ <xsl:apply-templates select="node()|@*" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="@*" />
+ <xsl:attribute name="wdef:id">
+ <xsl:value-of select="$new-id" />
+ </xsl:attribute>
+ <xsl:apply-templates select="node()" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="wdef:ref-element">
+ <xsl:copy>
+ <xsl:choose>
+ <xsl:when test=". = $old-id">
+ <xsl:value-of select="$new-id" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="node()|@*" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>