Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / filter-keep-only-select.xsl @ 187

History | View | Annotate | Download (3.3 kB)

1
<?xml version="1.0"?>
2
<xsl:stylesheet
3
  xmlns:xd="http://www.pnp-software.com/XSLTdoc"
4
  xmlns:edate="http://exslt.org/dates-and-times"
5
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0"
6
  exclude-result-prefixes="tei edate xd" version="2.0">
7
 
8
  <xd:doc type="stylesheet">
9
    <xd:short>
10
      Feuille de style de suppression de tous les éléments XML sauf "select",
11
      à utiliser comme prétraitement de l'import XML/w+CSV.
12
      
13
      Pour changer le nom de la balise à conserver, mettez le nouveau nom
14
      à la place de "select" dans la balise <xsl:param/> ci-dessous. Vous pouvez 
15
      mettre plusieurs noms en les séparant par une barre verticale. Vous 
16
      pouvez également indiquer le(s) nom(s) de balises à conserver comme un 
17
      paramètre au lancement de cette feuille de style
18
      
19
      L'espace de nommage de la balise à conserver n'est pas pris en compte.
20
    </xd:short>
21
    <xd:detail>
22
      This stylesheet is free software; you can redistribute it and/or
23
      modify it under the terms of the GNU Lesser General Public
24
      License as published by the Free Software Foundation; either
25
      version 3 of the License, or (at your option) any later version.
26
      
27
      This stylesheet is distributed in the hope that it will be useful,
28
      but WITHOUT ANY WARRANTY; without even the implied warranty of
29
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
30
      Lesser General Public License for more details.
31
      
32
      You should have received a copy of GNU Lesser Public License with
33
      this stylesheet. If not, see http://www.gnu.org/licenses/lgpl.html
34
    </xd:detail>
35
    <xd:author>Alexei Lavrentiev alexei.lavrentev@ens-lyon.fr</xd:author>
36
    <xd:copyright>2013, CNRS / ICAR (ICAR3 LinCoBaTO)</xd:copyright>
37
  </xd:doc>
38
  
39

    
40
  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no"/>
41
	
42
	<!-- Mettez le nom de la balise à conserver à la place de "select" ci-dessous -->
43
	<xsl:param name="tagToKeep">select</xsl:param>
44

    
45
	<xsl:variable name="tagToKeepStrict"><xsl:value-of select="concat('^',$tagToKeep,'$')"/></xsl:variable>
46

    
47
  <xsl:template match="@*|node()">
48
    <xsl:copy>
49
      <xsl:apply-templates select="@*|node()" />
50
    </xsl:copy>
51
  </xsl:template>
52

    
53

    
54
<xsl:template match="/">
55
  <xsl:apply-templates select="processing-instruction()"/>
56
  <xsl:choose>
57
    <xsl:when test="descendant::*[matches(local-name(),$tagToKeepStrict)]">
58
      <xsl:apply-templates mode="with-select"/>
59
    </xsl:when>
60
    <xsl:otherwise>
61
      <xsl:apply-templates/>
62
    </xsl:otherwise>
63
  </xsl:choose>
64
</xsl:template>
65

    
66
  <xsl:template match="*" mode="with-select">
67
    <xsl:choose>
68
    	<xsl:when test="ancestor-or-self::*[matches(local-name(),$tagToKeepStrict)]">
69
        <xsl:copy>
70
          <xsl:apply-templates select="@*|node()"/>
71
        </xsl:copy>      
72
      </xsl:when>
73
    	<xsl:when test="descendant::*[matches(local-name(),$tagToKeepStrict)]">
74
        <xsl:copy>
75
          <xsl:apply-templates select="@*"/>
76
        	<xsl:apply-templates select="*[descendant-or-self::*[matches(local-name(),$tagToKeepStrict)]]" mode="with-select"/>
77
        </xsl:copy>
78
      </xsl:when>
79
    </xsl:choose>
80
  </xsl:template>  
81
  
82
</xsl:stylesheet>