| 4 |
## $Id$ |
## $Id$ |
| 5 |
## ------------------------------------------------------------------------- |
## ------------------------------------------------------------------------- |
| 6 |
## $Log$ |
## $Log$ |
| 7 |
|
## Revision 1.2 2003/04/25 12:35:23 joko |
| 8 |
|
## added some pod |
| 9 |
|
## revamped xsl |
| 10 |
|
## |
| 11 |
## Revision 1.1 2003/04/24 21:07:36 joko |
## Revision 1.1 2003/04/24 21:07:36 joko |
| 12 |
## initial commit |
## initial commit |
| 13 |
## |
## |
| 35 |
access to the XPath API in libxml2. |
access to the XPath API in libxml2. |
| 36 |
|
|
| 37 |
|
|
| 38 |
=head3 In short: |
=head3 Yet another xupdate - facts in short: |
| 39 |
|
|
| 40 |
S: It would be nice to have a pure perl thingy which does the same stuff.... |
S: It would be nice to have a pure perl thingy which does (almost) the same stuff.... |
| 41 |
|
|
| 42 |
Q: Can we achieve compliance with its API? (just a subset ....) |
Q: Can we achieve compliance with its (XML::XUpdate::LibXML) API? (just a subset ....) |
| 43 |
|
|
| 44 |
Q: Can we achieve the processing declared as a XSL document processed using CPAN's XML::XSLT? |
Q: Can we achieve the processing declared as a XSL document processed using CPAN's XML::XSLT? |
| 45 |
|
|
| 47 |
|
|
| 48 |
Q: Can we mimic/use the interface of the - already established - 'xupdate' program??? |
Q: Can we mimic/use the interface of the - already established - 'xupdate' program??? |
| 49 |
|
|
| 50 |
|
Q: Should we follow the CRUD path first? |
| 51 |
|
|
| 52 |
|
|
| 53 |
=cut |
=cut |
| 54 |
|
|
| 107 |
<xsl:output method="raw"/> |
<xsl:output method="raw"/> |
| 108 |
|
|
| 109 |
<!-- 0. The root node dispatcher. --> |
<!-- 0. The root node dispatcher. --> |
| 110 |
<xsl:template match="*"><xsl:call-template name="passthru"/></xsl:template> |
<xsl:template match="*"><xsl:call-template name="passthru" /></xsl:template> |
| 111 |
<!-- <xsl:template match="source"><xsl:call-template name="insertChildNode"/></xsl:template> --> |
<xsl:template match="source"><xsl:call-template name="lock_context" /></xsl:template> |
| 112 |
|
|
| 113 |
<!-- 1. This is the passthru logic (copy all). --> |
<!-- 1. This is the passthru logic (copy all). --> |
| 114 |
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template> |
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template> |
| 115 |
|
|
|
<!-- 2. This is the manipulation logic: insertChildNode --> |
|
| 116 |
|
|
| 117 |
<!-- 2.a. The "API" method. --> |
<!-- 2. This is the crud API. --> |
|
<xsl:template name="insertChildNode"> |
|
| 118 |
|
|
| 119 |
<!-- manipulate node --> |
<!-- 2.a. The context finder. --> |
| 120 |
<xsl:comment> node - begin </xsl:comment> |
|
| 121 |
|
<xsl:template name="lock_context"> |
| 122 |
<!-- <xsl:copy-of select="source" /> --> |
<xsl:choose> |
|
<xsl:copy> |
|
| 123 |
|
|
| 124 |
<!-- Pass through children 1:1. --> |
<xsl:when test="@key=expekt"> |
| 125 |
<xsl:apply-templates /> |
<xsl:call-template name="inject_kay_motl" /> |
| 126 |
|
</xsl:when> |
| 127 |
|
|
| 128 |
<!-- Call one of the manipulators - this implements injection behavior. --> |
<xsl:otherwise> |
| 129 |
<xsl:call-template name="clone_last_element" /> |
<xsl:call-template name="passthru_kay" /> |
| 130 |
<xsl:call-template name="inject_template" /> |
</xsl:otherwise> |
| 131 |
|
|
| 132 |
</xsl:copy> |
</xsl:choose> |
|
<xsl:comment> node - end </xsl:comment> |
|
|
|
|
| 133 |
</xsl:template> |
</xsl:template> |
| 134 |
|
|
| 135 |
|
|
| 136 |
<!-- 2.b. The context finder. --> |
<!-- 2.b. The node manipulators: They translate the current context. --> |
| 137 |
|
|
| 138 |
|
<!-- by Mike Kay, Software AG [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] --> |
| 139 |
|
<!-- enhancements & comments: Andreas Motl, rotamente.de --> |
| 140 |
|
<!-- <xsl:template match="source"> --> |
| 141 |
|
<xsl:template name="passthru_kay"> |
| 142 |
|
<xsl:copy> |
| 143 |
|
<xsl:copy-of select="@*" /> |
| 144 |
|
<xsl:apply-templates /> |
| 145 |
|
</xsl:copy> |
| 146 |
|
</xsl:template> |
| 147 |
|
|
| 148 |
|
<xsl:template name="inject_kay_motl"> |
| 149 |
|
<xsl:copy> |
| 150 |
|
<xsl:copy-of select="@*" /> |
| 151 |
|
<xsl:apply-templates /> |
| 152 |
|
<!-- <xsl:apply-templates select="*[3]" /> --> |
| 153 |
|
<!-- <xsl:value-of select="text()" /> --> |
| 154 |
|
<!-- Multiple handlers here now: a) create fressshhhh element, b) clone s.th. --> |
| 155 |
|
<!-- TODO: Do switch/case or couple of if/then statements here to be able to handle that "at runtime". --> |
| 156 |
|
<xsl:call-template name="create_fresh_element" /> |
| 157 |
|
<xsl:call-template name="clone_last_element" /> |
| 158 |
|
<xsl:call-template name="clone_element_nr" /> |
| 159 |
|
</xsl:copy> |
| 160 |
|
</xsl:template> |
| 161 |
|
|
| 162 |
|
|
| 163 |
<!-- 2.c. The node manipulators: They mungle the current context. --> |
|
| 164 |
|
<!-- 2.c. The element manipulators: They mungle a specific element inside the current context. --> |
| 165 |
|
|
| 166 |
<!-- copy over node 1:1 (use last element as a template) --> |
<!-- copy over node 1:1 (use last element as a template) --> |
| 167 |
<xsl:template name="clone_last_element"> |
<xsl:template name="clone_last_element"> |
| 169 |
</xsl:template> |
</xsl:template> |
| 170 |
|
|
| 171 |
<xsl:template name="clone_element_nr"> |
<xsl:template name="clone_element_nr"> |
| 172 |
<xsl:copy-of select="*[last()]" /> |
<!-- TODO: let idx be passed in via "with-param" or s.th.l.th. --> |
| 173 |
|
<xsl:copy-of select="*[2]" /> |
| 174 |
</xsl:template> |
</xsl:template> |
| 175 |
|
|
| 176 |
<!-- creates instance of new element --> |
<!-- creates instance of new element --> |
| 186 |
</xsl:template> |
</xsl:template> |
| 187 |
|
|
| 188 |
|
|
|
<!-- Fine stuff from others. --> |
|
| 189 |
|
|
| 190 |
<!-- by Mike Kay, Software AG [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] --> |
|
| 191 |
<!-- enhancements & comments: Andreas Motl, rotamente.de --> |
<!-- 0. The root node dispatcher. --> |
| 192 |
<xsl:template match="source"> |
<!-- <xsl:template match="source"><xsl:call-template name="insertChildNode"/></xsl:template> --> |
| 193 |
|
|
| 194 |
|
<!-- 2. This is the manipulation logic: insertChildNode --> |
| 195 |
|
|
| 196 |
|
<!-- 2.a. The "API" method. - now deprecated --> |
| 197 |
|
<xsl:template name="insertChildNode"> |
| 198 |
|
|
| 199 |
|
<!-- manipulate node --> |
| 200 |
|
<xsl:comment> node - begin </xsl:comment> |
| 201 |
|
|
| 202 |
|
<!-- <xsl:copy-of select="source" /> --> |
| 203 |
<xsl:copy> |
<xsl:copy> |
| 204 |
<xsl:copy-of select="@*" /> |
|
| 205 |
|
<!-- Pass through children 1:1. --> |
| 206 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
| 207 |
<!-- multiple handlers here now: a) create fressshhhh element, b) clone s.th. --> |
|
| 208 |
<!-- TODO: Do switch/case or couple of if/then statements here to be able to handle that "at runtime". --> |
<!-- Call one of the manipulators - this implements injection behavior. --> |
|
<xsl:call-template name="create_fresh_element" /> |
|
| 209 |
<xsl:call-template name="clone_last_element" /> |
<xsl:call-template name="clone_last_element" /> |
| 210 |
</xsl:copy> |
<xsl:call-template name="inject_template" /> |
| 211 |
|
|
| 212 |
|
</xsl:copy> |
| 213 |
|
<xsl:comment> node - end </xsl:comment> |
| 214 |
|
|
| 215 |
</xsl:template> |
</xsl:template> |
| 216 |
|
|
| 217 |
|
|