Hi all,
I thought it would be a good idea to develop an XSLT implementation of Xupdate, the
idea is to transform an Xupdate script into an
XSLT stylesheet using XSLT and then use the XSLT stylesheet to modify the XML
document. With this tool you only need an
XSLT processor to be able to process Xupdate modifications. That would be very nice in
terms of portability.
I developed a prototype stylesheet that I'm including below but it has several
pitfalls and I think I need some help to get it working.
Problems:
The stylesheet can't update/remove/append/rename attributes.
It has problems with the xupdate:attribute construction
So If anyone is interested in helping me to develop this XSLT implementation just
write here or to my personal email [EMAIL PROTECTED]
Have a nice day,
Garland.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xsl:output method="xml" encoding="utf-8" />
<xsl:template match="//xupdate:modifications">
<xsl:element name="xsl:stylesheet">
<xsl:attribute name="xmlns:xsl">http://www.w3.org/1999/XSL/Transform</xsl:attribute>
<xsl:attribute name="version">1.0</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!-- This handles xupdate:attribute -->
<xsl:template match="//xupdate:attribute">
<xsl:attribute name="[EMAIL PROTECTED]"><xsl:value-of select="./text()"
/></xsl:attribute>
</xsl:template>
<!-- This handles xupdate:element -->
<xsl:template match="//xupdate:element">
<xsl:element name="[EMAIL PROTECTED]">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!-- This handles xupdate:text -->
<xsl:template match="//xupdate:text">
<xsl:value-of select="text()" />
</xsl:template>
<!-- This handles xupdate:processing-instruction -->
<!-- This handles xupdate:comment -->
<!-- This handles xupdate:cdata -->
<!-- This handles xupdate:update -->
<xsl:template match="//xupdate:update">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select" /></xsl:attribute>
<xsl:choose>
<xsl:when test="not(contains(./@select,\'@\'))">
<xsl:element name="xsl:element">
<xsl:attribute name="name">{name()}</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="xsl:message">Updating attributes is not supported
yet</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<!-- This handles xupdate:insert-before -->
<xsl:template match="//xupdate:insert-before">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select" /></xsl:attribute>
<xsl:apply-templates />
<xsl:element name="xsl:element">
<xsl:attribute name="name">{name()}</xsl:attribute>
<xsl:element name="xsl:apply-templates" />
</xsl:element>
</xsl:element>
</xsl:template>
<!-- This handles xupdate:insert-after -->
<xsl:template match="//xupdate:insert-after">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select" /></xsl:attribute>
<xsl:element name="xsl:element">
<xsl:attribute name="name">{name()}</xsl:attribute>
<xsl:element name="xsl:apply-templates" />
</xsl:element>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!-- This handles the xupdate:append -->
<!-- THIS IMPLEMENTATION IGNORES THE CHILD ATTRIBUTE MAKE THE CHILD ATTRIBUTE WORK
CHANGING THE
POSITION PREDICATE IS A TO-DO -->
<xsl:template match="//xupdate:append">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select"
/>[position()=count(.)]</xsl:attribute>
<xsl:element name="xsl:element">
<xsl:attribute name="name">{name()}</xsl:attribute>
<xsl:element name="xsl:apply-templates" />
<xsl:apply-templates select="*" />
</xsl:element>
</xsl:element>
</xsl:template>
<!-- This handles renames -->
<xsl:template match="//xupdate:rename">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select" /></xsl:attribute>
<xsl:element name="xsl:element">
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(text())"/>
</xsl:attribute>
<xsl:element name="xsl:apply-templates">
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- This handles remove -->
<xsl:template match="//xupdate:remove">
<xsl:element name="xsl:template">
<xsl:attribute name="match"><xsl:value-of select="./@select" /></xsl:attribute>
<!--<xsl:element name="xsl:element">
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(text())"/>
</xsl:attribute>
<xsl:element name="xsl:apply-templates">
</xsl:element>
</xsl:element>
-->
</xsl:element>
</xsl:template>
<!-- Copy template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.362 / Virus Database: 199 - Release Date: 5/10/02
--
______________________________________________________________________
Lars Martin mailto:[EMAIL PROTECTED]
SMB GmbH http://www.smb-tec.com
----------------------------------------------------------------------
Post a message: mailto:[EMAIL PROTECTED]
Unsubscribe: mailto:[EMAIL PROTECTED]
Contact administrator: mailto:[EMAIL PROTECTED]
Read archived messages: http://archive.xmldb.org/
----------------------------------------------------------------------