/[cvs]/nfo/perl/libs/XML/XUpdate/xupdate2xsl.xml
ViewVC logotype

Annotation of /nfo/perl/libs/XML/XUpdate/xupdate2xsl.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Thu May 1 23:42:48 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
Changes since 1.1: +73 -3 lines
File MIME type: text/xml
somehow got this working together with Mike Kay's identity template rule - very alpha and just "insert-after" seems to work ....

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed