]> Pierre Choffet | Git repositories - wdef_tools.git/commitdiff
Add canonicalize stylesheet
authorPierre Choffet <peuc@wanadoo.fr>
Fri, 24 Dec 2021 05:24:12 +0000 (00:24 -0500)
committerPierre Choffet <peuc@wanadoo.fr>
Fri, 24 Dec 2021 05:24:12 +0000 (00:24 -0500)
README [new file with mode: 0644]
xslts/canonicalize.xslt [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..ba9f599
--- /dev/null
+++ b/README
@@ -0,0 +1,23 @@
+wdef_tools - Collection of tools to work with Wdef files.
+
+Repository: https://git.choffet.net/?p=wdef_tools.git
+
+
+These tools are designed to work on valid Wdef files (see this repository for
+more information: https://git.choffet.net/?p=wdef_schemas.git ). Behavior when
+applying on non-compliant file is undefined.
+
+Runtime dependencies are:
+  - Bash - https://www.gnu.org/software/bash/
+    Shell script interpreter
+
+  - Wikibase-cli - https://github.com/maxlath/wikibase-cli
+    Interface to Wikidata operations
+
+  - Xmlstarlet - http://xmlstar.sourceforge.net/
+    XSD and XSLT processor
+
+
+Description of the provided tools:
+  - xslts/canonicalize.xslt
+    Return a wdef under its normal form.
diff --git a/xslts/canonicalize.xslt b/xslts/canonicalize.xslt
new file mode 100644 (file)
index 0000000..ae31a64
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- canonicalize.xslt - Rewrite a wdef file into its normal form.
+     Copyright (C) 2021  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:stylesheet version="1.0" xmlns:wdef="https://purl.choffet.net/wdef"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+       <xsl:output indent="yes" method="xml" encoding="utf-8" />
+       <xsl:strip-space elements="*" />
+       
+       <xsl:template match="node()|@*">
+               <xsl:copy>
+                       <xsl:apply-templates select="node()|@*" />
+               </xsl:copy>
+       </xsl:template>
+       
+       <!-- wdef:element with no child nodes -->
+       <xsl:template match="wdef:element[not(*)]" />
+       
+       <!-- Local-only wdef:element with no label -->
+       <xsl:template match="wdef:element[substring(@wdef:id, 1, 1) != 'Q' and not(wdef:label)]" />
+       
+       <!-- wdef:property with no child nodes -->
+       <xsl:template match="wdef:property[not(*)]" />
+       
+       <!-- wdef:value or wdef:novalue with no temporary @wdef:value and no qualifier -->
+       <xsl:template match="wdef:value[substring(@wdef:id, 1, 1) != '?' and not(wdef:qualifier)]" />
+       <xsl:template match="wdef:novalue[substring(@wdef:id, 1, 1) != '?' and not(wdef:qualifier)]" />
+       
+       <!-- wdef:qualifier with no wdef:value having temporary @wdef:id -->
+       <xsl:template match="wdef:qualifier[wdef:property/wdef:value[substring(@wdef:id, 1, 1) != '?']]" />
+</xsl:stylesheet>