]>
Pierre Choffet | Git repositories - wdef_tools.git/blob - 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
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.
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.
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/>.
19 <xsl:output method=
"xml" encoding=
"utf-8" />
21 <xsl:param name=
"old-id" />
22 <xsl:param name=
"new-id" />
24 <xsl:template match=
"@*">
26 <xsl:apply-templates select=
"@*" />
30 <xsl:template match=
"node()">
33 <xsl:when test=
"not(@wdef:id) or @wdef:id != $old-id">
34 <xsl:apply-templates select=
"node()|@*" />
37 <xsl:apply-templates select=
"@*" />
38 <xsl:attribute name=
"wdef:id">
39 <xsl:value-of select=
"$new-id" />
41 <xsl:apply-templates select=
"node()" />
47 <xsl:template match=
"wdef:ref-element">
50 <xsl:when test=
". = $old-id">
51 <xsl:value-of select=
"$new-id" />
54 <xsl:apply-templates select=
"node()|@*" />