-
Notifications
You must be signed in to change notification settings - Fork 0
/
xsl2pxsl.xsl
60 lines (47 loc) · 1.9 KB
/
xsl2pxsl.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "text"/>
<xsl:template match = "/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match = "*">
<xsl:if test = "self::xsl:template">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:call-template name = "output-indent"/>
<xsl:value-of select = "name()"/>
<xsl:for-each select = "@*">
<xsl:text> -</xsl:text>
<xsl:value-of select = "name()"/>
<xsl:text>=</xsl:text>
<xsl:choose><xsl:when test = "contains(.,' ') or contains(.,')>')">
<xsl:value-of select = "concat('<{',string(.),'}>')"/>
</xsl:when><xsl:otherwise>
<xsl:value-of select = "string(.)"/>
</xsl:otherwise></xsl:choose>
</xsl:for-each>
<xsl:if test = "self::xsl:stylesheet">
<xsl:for-each select = "namespace::*">
<xsl:text> -xmlns:</xsl:text>
<xsl:value-of select = "name()"/>
<xsl:text>=</xsl:text>
<xsl:value-of select = "string(.)"/>
</xsl:for-each>
</xsl:if>
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match = "text()">
<xsl:if test = "normalize-space(.) != ''">
<xsl:call-template name = "output-indent"/>
<xsl:text disable-output-escaping = 'yes'><![CDATA[<<]]></xsl:text>
<xsl:value-of select = "."/>
<xsl:text disable-output-escaping = 'yes'><![CDATA[>>]]>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name = "output-indent">
<xsl:for-each select = "ancestor::*">
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>