]> Pierre Choffet | Git repositories - wdef_tools.git/commitdiff
Add stylesheet to remove labels and descriptions in a given element
authorPierre Choffet <peuc@wanadoo.fr>
Tue, 11 Jan 2022 22:36:32 +0000 (17:36 -0500)
committerPierre Choffet <peuc@wanadoo.fr>
Tue, 11 Jan 2022 22:36:32 +0000 (17:36 -0500)
README
xslts/remove_labels_descriptions.xslt [new file with mode: 0644]

diff --git a/README b/README
index 9006401859a5ed24648fa8b256d7616a8baf0ff1..ce966d130b3285dfc2d8bf6bf236340128d4ab42 100644 (file)
--- a/README
+++ b/README
@@ -25,5 +25,8 @@ Description of the provided tools:
   - xslts/canonicalize.xslt
     Return a wdef under its normal form.
 
+  - xslts/remove_labels_descriptions.xslt
+    Return a wdef with labels and description removed for a given element.
+
   - xslts/replace_id.xslt
     Change the wdef:id of an element and its references.
diff --git a/xslts/remove_labels_descriptions.xslt b/xslts/remove_labels_descriptions.xslt
new file mode 100644 (file)
index 0000000..a84c83a
--- /dev/null
@@ -0,0 +1,37 @@
+<?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">
+<!-- remove_labels_descriptions.xslt - Remove labels and descritions in an element.
+     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" indent="yes" />
+       <xsl:strip-space elements="*"/>
+       
+       <xsl:param name="wdef-id" />
+       
+       <xsl:template match="node()|@*">
+               <xsl:copy>
+                       <xsl:apply-templates select="node()|@*" />
+               </xsl:copy>
+       </xsl:template>
+       
+       <xsl:template match="wdef:label|wdef:description">
+               <xsl:if test="not(../@wdef:id) or ../@wdef:id != $wdef-id">
+                       <xsl:copy>
+                               <xsl:apply-templates select="node()|@*" />
+                       </xsl:copy>
+               </xsl:if>
+       </xsl:template>
+</xsl:stylesheet>