]> Pierre Choffet | Git repositories - wdef_tools.git/blob - xslts/replace_id.xslt
Add script to compare with Wikidata’s RDF
[wdef_tools.git] / xslts / replace_id.xslt
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:wdef="https://purl.choffet.net/wdef"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4 <!-- replace_id.xslt - Replace wdef id value while keeping references in sync.
5 Copyright (C) 2020, 2021, 2022 Pierre Choffet
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of version 3 of the GNU General Public License as
9 published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 -->
19 <xsl:output method="xml" encoding="utf-8" />
20
21 <xsl:param name="old-id" />
22 <xsl:param name="new-id" />
23
24 <xsl:template match="@*">
25 <xsl:copy>
26 <xsl:apply-templates select="@*" />
27 </xsl:copy>
28 </xsl:template>
29
30 <xsl:template match="node()">
31 <xsl:copy>
32 <xsl:choose>
33 <xsl:when test="not(@wdef:id) or @wdef:id != $old-id">
34 <xsl:apply-templates select="node()|@*" />
35 </xsl:when>
36 <xsl:otherwise>
37 <xsl:apply-templates select="@*" />
38 <xsl:attribute name="wdef:id">
39 <xsl:value-of select="$new-id" />
40 </xsl:attribute>
41 <xsl:apply-templates select="node()" />
42 </xsl:otherwise>
43 </xsl:choose>
44 </xsl:copy>
45 </xsl:template>
46
47 <xsl:template match="wdef:ref-element">
48 <xsl:copy>
49 <xsl:choose>
50 <xsl:when test=". = $old-id">
51 <xsl:value-of select="$new-id" />
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:apply-templates select="node()|@*" />
55 </xsl:otherwise>
56 </xsl:choose>
57 </xsl:copy>
58 </xsl:template>
59 </xsl:stylesheet>