update from latest MirBSD CVS
[shellsnippets/shellsnippets.git] / mksh / mvnrepo.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3         This XSLT 1.0 file, converting XML to an XPath string list, is:
4         Copyright © 2018 mirabilos <t.glaser@tarent.de>
5         Licensor: tarent solutions GmbH, Bonn
6
7         This is a derivative work of an original Work retrieved from the
8         StackOverflow/StackExchange network, whose Original Author is:
9         © 2011 Dimitre Novatchev <https://stackoverflow.com/users/36305>
10         Source: https://stackoverflow.com/a/4747858/2171120
11         Question by ant <https://stackoverflow.com/users/169277>
12
13         Further incorporated works from the same site are by:
14
15         © 2014 Sam Harwell <https://stackoverflow.com/users/138304>
16         Source: https://stackoverflow.com/a/24831920/2171120
17         Question by Mithil <https://stackoverflow.com/users/34219>
18
19         © 2011 Mads Hansen <https://stackoverflow.com/users/14419>
20         Source: https://stackoverflow.com/a/7523245/2171120
21         Question by Paul <https://stackoverflow.com/users/925899>
22
23         This Adaption may be Distributed or Publicly Performed under the
24         CC-BY-SA 3.0 (unported) licence or (at Your option) any later
25         version of that licence, as published by Creative Commons, with
26         no associated URI or title of the Work supplied. Licence URI:
27         https://creativecommons.org/licenses/by-sa/3.0/legalcode.txt
28 -->
29 <!DOCTYPE xsl:stylesheet [
30 <!ENTITY nl "&#x0A;">
31 ]>
32 <!-- https://stackoverflow.com/a/4747858/2171120 -->
33 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
34         <xsl:output method="text" encoding="UTF-8" indent="no"/>
35         <xsl:strip-space elements="*"/>
36         <xsl:variable name="sq">'</xsl:variable>
37         <xsl:template name="quote">
38                 <xsl:param name="str"/>
39                 <xsl:choose>
40                         <xsl:when test="contains($str, $sq)">
41                                 <xsl:value-of select="substring-before($str, $sq)"/>
42                                 <xsl:text>'\''</xsl:text>
43                                 <xsl:call-template name="quote">
44                                         <xsl:with-param name="str" select="substring-after($str, $sq)"/>
45                                 </xsl:call-template>
46                         </xsl:when>
47                         <xsl:otherwise>
48                                 <xsl:value-of select="$str"/>
49                         </xsl:otherwise>
50                 </xsl:choose>
51         </xsl:template>
52         <xsl:template name="renderEQvalue">
53                 <xsl:text>='</xsl:text>
54                 <xsl:call-template name="quote">
55                         <xsl:with-param name="str" select="."/>
56                 </xsl:call-template>
57         </xsl:template>
58         <xsl:template match="*[@* or not(*)]">
59                 <xsl:if test="not(*)">
60                         <xsl:text>/</xsl:text>
61                         <xsl:apply-templates select="ancestor-or-self::*" mode="path"/>
62                         <xsl:call-template name="renderEQvalue"/>
63                         <xsl:text>'&nl;</xsl:text>
64                 </xsl:if>
65                 <xsl:apply-templates select="@*|*"/>
66         </xsl:template>
67         <xsl:template match="*" mode="path">
68                 <xsl:value-of select="concat('/', name())"/>
69                 <xsl:variable name="precSiblings" select="count(preceding-sibling::*[name()=name(current())])"/>
70                 <xsl:variable name="nextSiblings" select="count(following-sibling::*[name()=name(current())])"/>
71                 <xsl:if test="$precSiblings or $nextSiblings">
72                         <xsl:value-of select="concat('[', $precSiblings + 1, ']')"/>
73                 </xsl:if>
74         </xsl:template>
75         <xsl:template match="@*">
76                 <xsl:text>/</xsl:text>
77                 <xsl:apply-templates select="../ancestor-or-self::*" mode="path"/>
78                 <xsl:text>[@</xsl:text>
79                 <xsl:value-of select="name()"/>
80                 <xsl:call-template name="renderEQvalue"/>
81                 <xsl:text>']&nl;</xsl:text>
82         </xsl:template>
83 </xsl:stylesheet>