Solved

I need a generic XSLT stylesheet to transform to XForms document

Posted on 2007-11-16
11
938 Views
Last Modified: 2013-11-18
Consider an XML document like the one below. How can we write a generic XSLT stylesheet to transform this document to an XForms document? Transformation is based on the value of <type> and <nullable> elements. i.e all information we have is the data type of element and whether it accepts null values or not. In addition, the label of Xforms element form takes its value from <label> node.
Please bear in mind that the XSLT stylesheet must bee generic. i.e Reusable for any XML document with any number of <element> nodes.

<login>
   <element>
           <label> User ID </label>
          <type> integer </type>
           <nullable> false </nullable>
   </element>
   <element > 
             <label> Password </label>
            <type> string </type>
            <nullable> false </nullable>
   </element>
   <element > 
             <label> D.o.Birth </label>
            <type> date </type>
            <nullable> true </nullable>
   </element>
</login>

Each XML node must be mapped to a specific XForms UI element. Mapping should be based on the <type> node. i.e if <type> is string or integer it should be mapped to <input ref=”string”…>. If type is <boolean> then mapped it to <select1>. If it is date then it should be mapped to <input ref=”date”…>. Also, node <nullable> … </nullable> must be used to validate the entry date null or not

I tried writing this and I have the following;

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="element[normalize-space(type) = 'string']">
<input ref="string">
<label><xsl:value-of select="normalize-space(label)"/></label>
<bind nodeset="/login/element">
<xsl:attribute name="required">
<xsl:apply-templates select="nullable"/>
</xsl:attribute>
</bind>
</input>
</xsl:template>

<xsl:template match="element[normalize-space(type) = 'integer']">
<input ref="string">
<label><xsl:value-of select="normalize-space(label)"/></label>
<bind nodeset="/login/element">
<xsl:attribute name="required">
<xsl:apply-templates select="nullable"/>
</xsl:attribute>
</bind>
</input>
</xsl:template>

<xsl:template match="element[normalize-space(type) = 'boolean']">
<select1 ref="boolean">
<bind nodeset="/login/element">
<xsl:attribute name="required">
<xsl:apply-templates select="nullable"/>
</xsl:attribute>
</bind>
</select1>
</xsl:template>

<xsl:template match="element[normalize-space(type) = 'date']">
<input ref="date">
<label><xsl:value-of select="normalize-space(label)"/></label>
<bind nodeset="/login/element">
<xsl:attribute name="required">
<xsl:apply-templates select="nullable"/>
</xsl:attribute>
</bind>
</input>
</xsl:template>

<xsl:template match="null">
<xsl:choose>
<xsl:when test="normalize-space(.) = 'false'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>


However, when I transfer the xml doc using the above xslt stylesheet, I get an xml doc and not XForms doc. (you can do a View Source to see this)
So, I think the above xslt stylesheet needs some extra work to consider the following
a) we need to build up the <xforms:model> which contains the <xforms:instance> and binding each instance elemet to a specific xforms control element.
b) The xforms control elements must be placed between <body> and </body> tags.

Thus, basicall I require a complete xslt document (based on the above doc), which includes
<xsl:output method =”xhtml” /> and placing each part of it between the right tags (<html> <head> <body>).

The Platform is Windows XP and the browser is X-smiles.

Thanks in advance for all your help.
0
Comment
Question by:askanyquestions123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 

Author Comment

by:askanyquestions123
ID: 20303511
I am readding the code related information, which is not clearly visible above;

each XML node must be mapped to a specific XForms UI element. Mapping should be based on the <type> node. i.e if <type> is string or integer it should be mapped to <input ref=”string”…>. If type is <boolean> then mapped it to <select1>. If it is date then it should be mapped to <input ref=”date”…>. Also, node <nullable> … </nullable> must be used to validate the entry date null 
-------------------------------------------
 
Thus, basically I require a complete xslt document (based on the above doc), which includes
<xsl:output method =”xhtml” /> and placing each part of it between the right tags (<html> <head> <body>).

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 20303626
what is the point asking this question again if you don't answer the questions asked in your previous question?
0
 

Author Comment

by:askanyquestions123
ID: 20303637
Well you can always check out the examples. You can alos try getting more from;
http://www.xsmiles.org/demo/demos.xml
0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 

Author Comment

by:askanyquestions123
ID: 20303646
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:html="http://www.w3.org/1999/xhtml"
 xmlns:xfm="http://www.w3.org/2000/12/xforms" version="1.0">
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="/*">
      <html:html>
            <html:head>
                  <html:link href="controls.css" rel="stylesheet" type="text/css"/>
                  <html:style type="text/css">              
                        .section {background-color: #cccccc; border-width:2px; margin-bottom: 10px; padding-bottom: 5px;margin-left:30px;border-style:solid;}
                        h1 {font-size:18px; color:blue; margin-bottom: 8px;}
                        h2 {align: center;background-color:blue; color:white; margin-bottom: 3px; padding-left: 5px;margin-top:0px;}
                        .bookmark {padding-left: 10px; font-weight: bold; margin-bottom: 1px; margin-top: 1px;}
                  </html:style>
            </html:head>
            <html:body>
                  <html:h1>My Bookmarks</html:h1>
                  <xsl:apply-templates select="document('bookmarks2.xml')/bookmarks/section"/>
            </html:body>
      </html:html>
      </xsl:template>
      <!-- *************** section *******************-->
      <xsl:template match="section">
      <html:div class="section">
            <html:h2><xsl:value-of select="@name"/></html:h2>
            <xsl:apply-templates select="bookmark|section"/>
      </html:div>
      </xsl:template>
      <!-- *************** bookmark *******************-->
      <xsl:template match="bookmark">
            <html:p class="bookmark"><a href="{@href}" target="documentwindow"><xsl:value-of select="@name"/></a>
            </html:p>
      </xsl:template>
</xsl:stylesheet>



************

<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/*">
    <html>
      <head>
      <link rel="stylesheet" type="text/css" href="player.css" />
      </head>
      <body>
      <p>
        <xsl:apply-templates select="img|name|nationality|weight|height|goals|birthdate|caps|club"/>
      </p>
      <p>
        <xsl:apply-templates select="bio"/>
      </p>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="name">
     <b><xsl:value-of select="."/></b><br/>
  </xsl:template>

  <xsl:template match="img">
    <img src="{@src}" alt=""/><br/>
  </xsl:template>

  <xsl:template match="nationality"><b>Nationality:</b> <xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="position"><b>Position: </b><xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="height"><b>Height: </b><xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="weight">
      <b>Weight: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="goals">
      <b>Goals: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="caps">
      <b>Caps: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="club">
      <b>Club: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="birthdate">
    <b>Birthdate: </b><xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="bio">
      <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>
******************************************

<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/*">
    <html>
      <head>
      <link rel="stylesheet" type="text/css" href="player.css" />
      </head>
      <body>
      <p>
        <xsl:apply-templates select="img|name|nationality|weight|height|goals|birthdate|caps|club"/>
      </p>
      <p>
        <xsl:apply-templates select="bio"/>
      </p>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="name">
     <b><xsl:value-of select="."/></b><br/>
  </xsl:template>

  <xsl:template match="img">
    <img src="{@src}" alt=""/><br/>
  </xsl:template>

  <xsl:template match="nationality"><b>Nationality:</b> <xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="position"><b>Position: </b><xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="height"><b>Height: </b><xsl:value-of select="."/><br/></xsl:template>

  <xsl:template match="weight">
      <b>Weight: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="goals">
      <b>Goals: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="caps">
      <b>Caps: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="club">
      <b>Club: </b><xsl:value-of select="."/><br/>
  </xsl:template>

  <xsl:template match="birthdate">
    <b>Birthdate: </b><xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="bio">
      <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20303897
my last post in
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XSLT/Q_22955197.html
explains why this is not enough

cheers

Geert
0
 

Author Comment

by:askanyquestions123
ID: 20314208
Hello,

I have 2 examples. The first is very simple. But, the most important is the second one. However, the only thing to keep inmind is that the second example uses a static XSLT stylesheet whereas I am looking for a generic one. In addition, the structure of XML doc is slightly different.

http://xforms-examples.googlecode.com/svn/trunk/01-intro/01.hello-world/01-hello-world.xhtml

http://www.stylusstudio.com/xsllist/200304/post60900.html#

Thank you.
0
 

Author Comment

by:askanyquestions123
ID: 20321614
Hi there,

I am waiting for your reply.
Thank you.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20356406
well, I have been away for some time,
you can pose this question another ten times,
it will only help if you give the right information

The examples you post are not really helpfull
All I am asking is an XHTML document that works for you in XSmiles
not an XSLT, not something else

What I expect you to do is a little effort,
give me an example of an XForms that works in XSmiles,
one that you construct manually
If you do that, I can see the namespaces and give you the XSLT

There are some flavours of XForms and bindings and there are specific styles per framework
I am not going to figure out what will work for you in XSmiles,
you should do that yourself.
If you can't do that, I am afraid I can't help you

You have about a dozen open questions that are more or less the same,
but you fail to answer simple questions in return
Please understand that the ball is in your camp and that opening another dozen questions will not help you further in getting an answer

cheers

Geert
0
 

Author Comment

by:askanyquestions123
ID: 20367416
Here is a very simple XForms doc which is constructed manually.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:my="test" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<head>

<title>Hello XForms!</title>

<xforms:model id="form1">

<xforms:instance xmlns="">

<Name xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:my="test" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

</xforms:instance>

</xforms:model>

</head>

<body>

<xforms:input ref="/Name">

<xforms:label>Type your name in the box and press tab: </xforms:label>

</xforms:input>

<p>

<xforms:output value="concat('Hello ', /Name)">

<xforms:label>Output: </xforms:label>

</xforms:output>

</p>

</body>

</html>

However, in our case:
1- Instance data must be constructed and placed in <xforms:model> part.
2- Each XForms control must be binding to instance data node.
3- <xsl:for-each> loop is needed to loop through the XML doc in order to construct the instance data and XForms controls.
4- Mapping each XML node depends on <type> XXXX </type> node. Let us assume the rules for demonstration purpose.
· If <type> date </type> map it to <xforms:input ref="date"> <xforms:label> columnName </xforms:label> ...
</xforms:input>

· If <type> boolean </type> map it to <xforms:select1 ref="XXX"> <xforms:label> columnName </xforms:label> ... </xforms:select1>

If we success to generate the required doc. Countless rules can be added with little effort.
I hope that these hints are useful.


Another example: http://www.xsmiles.org/demo/testsuite/xforms/controls.xhtml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">-->
 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:my="test" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
<head>
 
<title>Hello XForms!</title>
 
<xforms:model id="form1">
 
<xforms:instance xmlns="">
 
<Name xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:my="test" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
 
</xforms:instance>
 
</xforms:model>
 
</head>
 
<body>
 
<xforms:input ref="/Name">
 
<xforms:label>Type your name in the box and press tab: </xforms:label>
 
</xforms:input>
 
<p>
 
<xforms:output value="concat('Hello ', /Name)">
 
<xforms:label>Output: </xforms:label>
 
</xforms:output>
 
</p>
 
</body>
 
</html>

Open in new window

0
 

Author Closing Comment

by:askanyquestions123
ID: 31409712
Closing this questions, as I have another open question, for which I am awaiting reply.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question