[xslt] xforms processor in pure xslt
- From: Bernhard Zwischenbrugger <bz datenkueche com>
- To: xslt gnome org
- Subject: [xslt] xforms processor in pure xslt
- Date: Mon, 13 Aug 2001 00:58:00 +0200
I try to implement a (server side) xforms (http://www.w3.orf/xforms) processor
in pure xslt.
It's not very difficult to do that, but there is one thing I can't solve.
Maybe the concept is wrong, but maybe there is a simple solution.
The xforms processor should translate xhtml+xforms to html+forms.
There will be a second XSLT Stylesheet that evaluates the URL (including GET
data) and generate a new XML File (data.xml).
Please have a look at the following example:
XHTML+XForms (model.xml)
============
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- -->
<!-- this is a simplified xforms example -->
<!-- this is pseudo code only -->
<!-- -->
<form xmlns:xfm="http://www.w3.org/2000/12/xforms"
xmlns="http://www.w3.org/2000/xhtml">
<xfm:xform id="form1">
<xfm:instance id="instance1" xlink:href="data.xml" />
</xfm:xform>
<h1>XForms model in X-Smiles</h1>
<p>The model in XForms defines the allowed content of form fields</p>
<xfm:textbox xform="form1" ref="/all/one" cols="20">
<xfm:caption>Name</xfm:caption>
<xfm:instance>/all/one</xfm:instance>
</xfm:textbox>
</form>
XSLT:
=====
<?xml version="1.0" encoding="UTF-8"?>
<!-- -->
<!-- (C) 2001 LGPL-->
<!-- author:Bernhard Zwischenbrugger -->
<!-- email: bz@datenkueche.com
<!-- -->
<!-- This isn't a working example !! -->
<!-- -->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
xmlns:xfm="http://www.w3.org/2000/12/xforms"
xmlns:xlink="http://www.w3.org/2000/xlink"
xmlns="http://www.w3.org/2000/xhtml"
>
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- -->
<!-- copy html to output, replace xforms by html forms -->
<!-- -->
<xsl:template match="*">
<xsl:choose>
<xsl:when test="self::xfm:*">
<xsl:call-template name="xforms"/>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}" select="{text()}"/>
</xsl:for-each>
<xsl:apply-templates select="*|text()"/>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- -->
<!-- select the xforms -->
<!-- -->
<xsl:template name="xforms">
<xsl:value-of select="xfm:caption"/>
<!-- Textbox -->
<xsl:if test="name()='xfm:textbox'">
<xsl:call-template name="textbox"/>
</xsl:if>
<br/>
</xsl:template>
<!-- -->
<!-- translate xforms elements to html forms -->
<!-- -->
<xsl:template name="textbox">
<input type="text" action="{@xform}" name="{@ref}" size="{@cols}">
<xsl:attribute name="value">
<!-- -->
<!-- #### Here is the big problem ####-->
<!-- -->
<xsl:value-of
select="libxslt:node-set(document(//xfm:form/xfm:instance/@href)/$instance)"/>
<!-- -->
<!-- #### End of big problem ####-->
<!-- -->
</xsl:attribute>
</input>
</xsl:template>
</xsl:stylesheet>
data.xml
======
<?xml version="1.0"?>
<all>
<one>first</one>
<two>second</two>
</all>
The problem is to get values from data.xml to fill the
form elements with default data.
It's possible to get the path to the data.xml from model.xml.
But as I know, it isn't possible to get an xpath value from model.xml
and select a value from data.xml using the xpath of the <instance> tag
in the model.xml.
Is there a simple solution for this problem?
Is it possible to write an extension function for this?
I know, using DOM it shouldn't be a big deal to imlement an xforms
processor, but XSLT is the language I like.
thanx
Bernhard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]