2 |
|
|
3 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
4 |
|
|
5 |
<!-- |
<!-- |
6 |
|
|
7 |
|
xupdate2xsl: Translate XML document from namespace 'xupdate' to 'xsl'. |
8 |
|
|
9 |
Purpose of this XML Stylesheet is to implement a set of templates |
Purpose of this XML Stylesheet is to implement a set of templates |
10 |
to translate XUpdate lingo into an intermediate xslt stylesheet |
to translate XUpdate lingo into an intermediate xslt stylesheet |
11 |
which actually performs the update to the original xml document |
which actually performs the update to the original xml document |
12 |
in a second step. |
in a second step. |
13 |
|
|
14 |
The required glue code - written in Perl - is available in module |
The required glue code - written in Perl - is available in module |
15 |
XML::XUpdate::XSLT. Please have a look at this to port it to other |
XML::XUpdate::XSLT. Please have a look at this in order to use |
16 |
languages. |
this stylesheet from other bindings. |
17 |
|
|
18 |
--> |
--> |
19 |
|
|
20 |
<xsl:output method="xml" /> |
<xsl:output method="xml" /> |
26 |
<!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule --> |
<!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule --> |
27 |
<xsl:template match="comment()"><xsl:call-template name="passthru" /></xsl:template> |
<xsl:template match="comment()"><xsl:call-template name="passthru" /></xsl:template> |
28 |
|
|
29 |
|
|
30 |
<!-- 2. This is the translation part: XUpdate becomes XSLT --> |
<!-- 2. This is the translation part: XUpdate becomes XSLT --> |
31 |
|
|
32 |
<!-- This node "encapsulates" common infrastructure. --> |
<!-- lib --> |
33 |
|
<!-- This node "encapsulates" common core infrastructure. --> |
34 |
<xsl:template match="xupdate:modifications"> |
<xsl:template match="xupdate:modifications"> |
35 |
|
|
36 |
|
<!-- <xsl:template name="identity_template_rule"> --> |
37 |
|
<xsl:element name="xsl:template"> |
38 |
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
39 |
|
|
40 |
|
<!-- An "identity template rule" - original version by Mike Kay, Software AG --> |
41 |
|
<!-- Please visit [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] --> |
42 |
|
<!-- Translated to "self hosting xsl": Andreas Motl, andreas.motl@ilo.de --> |
43 |
|
<!-- FIXME: Could this be used to replace passthru-logic at 1. ? --> |
44 |
|
<xsl:element name="xsl:copy"> |
45 |
|
<xsl:element name="xsl:copy-of"> |
46 |
|
<xsl:attribute name="select">@*</xsl:attribute> |
47 |
|
</xsl:element> |
48 |
|
<xsl:element name="xsl:apply-templates" /> |
49 |
|
</xsl:element> |
50 |
|
|
51 |
|
</xsl:element> |
52 |
|
<!-- </xsl:template> --> |
53 |
|
|
54 |
<!-- 1. This is the passthru logic (copy all untouched nodes). --> |
<!-- 1. This is the passthru logic (copy all untouched nodes). --> |
55 |
<!-- in fact this is the xsl from above translated to be able to be generated by xsl itself! --> |
<!-- in fact this is the xsl from above translated to be able to be generated by xsl itself! --> |
56 |
<xsl:comment> 1. passthru logic </xsl:comment> |
<xsl:comment> 1. passthru logic </xsl:comment> |
59 |
<xsl:element name="xsl:copy"><xsl:element name="xsl:apply-templates" /></xsl:element> |
<xsl:element name="xsl:copy"><xsl:element name="xsl:apply-templates" /></xsl:element> |
60 |
</xsl:element> |
</xsl:element> |
61 |
<xsl:element name="xsl:template"> |
<xsl:element name="xsl:template"> |
62 |
<xsl:attribute name="match">*</xsl:attribute> |
<!-- <xsl:attribute name="match">*</xsl:attribute> --> |
63 |
|
<xsl:attribute name="match">*ab</xsl:attribute> |
64 |
<xsl:element name="xsl:call-template"><xsl:attribute name="name">passthru</xsl:attribute></xsl:element> |
<xsl:element name="xsl:call-template"><xsl:attribute name="name">passthru</xsl:attribute></xsl:element> |
65 |
</xsl:element> |
</xsl:element> |
66 |
<xsl:element name="xsl:template"> |
<xsl:element name="xsl:template"> |
73 |
|
|
74 |
</xsl:template> |
</xsl:template> |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
<!-- code --> |
81 |
<!-- This node "encapsulates" infrastructure for handling the directives. --> |
<!-- This node "encapsulates" infrastructure for handling the directives. --> |
82 |
|
<!-- FIXME: handle the other ones: append, remove, etc. --> |
83 |
<xsl:template match="xupdate:insert-after"> |
<xsl:template match="xupdate:insert-after"> |
84 |
<xsl:comment> 2. context finder </xsl:comment> |
<xsl:comment> 2. context finder </xsl:comment> |
85 |
<xsl:apply-templates /> |
<!-- <xsl:variable name="select" select="@select">Hello World!</xsl:variable> --> |
86 |
|
|
87 |
|
<!-- this resembles some parts of the CRUD API - retranslated to self-hosting xsl --> |
88 |
|
|
89 |
|
<!-- V1 --> |
90 |
|
<!-- <xsl:element name="xsl:template"> --> |
91 |
|
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
92 |
|
|
93 |
|
<!-- V2 --> |
94 |
|
<xsl:element name="xsl:template"> |
95 |
|
<xsl:attribute name="match">*</xsl:attribute> |
96 |
|
<!-- <xsl:attribute name="match">/addresses/address</xsl:attribute> --> |
97 |
|
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
98 |
|
|
99 |
|
<xsl:element name="xsl:choose"> |
100 |
|
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
101 |
|
<xsl:element name="xsl:when"> |
102 |
|
<!-- <xsl:attribute name="test"><xsl:value-of select="@test" /></xsl:attribute> --> |
103 |
|
<xsl:attribute name="test"><xsl:value-of select="@select" /></xsl:attribute> |
104 |
|
|
105 |
|
<!-- FIXME: case "insert-before"!!! --> |
106 |
|
<!-- <xsl:apply-templates /> --> |
107 |
|
|
108 |
|
<!-- call the "identity template rule" to passthru all childnodes --> |
109 |
|
<xsl:element name="xsl:call-template"> |
110 |
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
111 |
|
<!-- <xsl:attribute name="name">passthru</xsl:attribute> --> |
112 |
|
</xsl:element> |
113 |
|
|
114 |
|
<!-- FIXME: case "insert-after"!!! --> |
115 |
|
<xsl:apply-templates /> |
116 |
|
|
117 |
|
</xsl:element> |
118 |
|
<xsl:element name="xsl:otherwise"> |
119 |
|
|
120 |
|
<!-- call the "identity template rule" to passthru all childnodes --> |
121 |
|
<xsl:element name="xsl:call-template"> |
122 |
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
123 |
|
<!-- <xsl:attribute name="name">passthru</xsl:attribute> --> |
124 |
|
</xsl:element> |
125 |
|
|
126 |
|
<!-- <xsl:apply-templates /> --> |
127 |
|
|
128 |
|
</xsl:element> |
129 |
|
|
130 |
|
</xsl:element> |
131 |
|
</xsl:element> |
132 |
|
|
133 |
|
<!-- <xsl:apply-templates /> --> |
134 |
|
|
135 |
</xsl:template> |
</xsl:template> |
136 |
|
|
137 |
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
138 |
<xsl:template match="xupdate:element"> |
<xsl:template match="xupdate:element"> |
139 |
<xsl:comment> 3. rewrite / vivify elements/attributes </xsl:comment> |
<xsl:comment> 3.a. vivify elements </xsl:comment> |
140 |
<xsl:element name="xsl:element"> |
<xsl:element name="xsl:element"> |
141 |
<xsl:copy-of select="@*"/> |
<xsl:copy-of select="@*"/> |
142 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
145 |
|
|
146 |
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
147 |
<xsl:template match="xupdate:attribute"> |
<xsl:template match="xupdate:attribute"> |
148 |
|
<xsl:comment> 3.b. vivify attributes </xsl:comment> |
149 |
<xsl:element name="xsl:attribute"> |
<xsl:element name="xsl:attribute"> |
150 |
<xsl:copy-of select="@*"/> |
<xsl:copy-of select="@*"/> |
151 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |