Solved

xml / xsl / html Form

Posted on 2012-03-16
8
516 Views
Last Modified: 2012-03-16
Hello,

I am working with some pre-existing code and don't know much of anything about xml.  I have an xml file that contains form data elements.  I have an xsl file that is supposed to create an html wrapper around those elements along with submission buttons.  I am not really sure what to write in the xsl file in order to render the form input elements.  The line that I was hoping would render my first name text input is:
<xsl:value-of select=" BIOForm /FirstName"/>
But that isn't rendering anything at all.

Help would be greatly appreciated.  
Note that I cannot change the xml/xsl methodology being used.    

Here is the beginning of my xml:
<?xml version="1.0" encoding="UTF-8"?>
<formView>
<formData>
<artifact>
<metaData>
<displayName/>
<type>
<id>file</id>
<description>file</description>
</type>
</metaData>
<structuredData>
<ISD621_Intro/>
</structuredData>
<schema>

<instructions>Fill out this form</instructions>
<element name="BIOForm" minOccurs="1" maxOccurs="1">
<children>
<element name="FirstName" type="xs:token" minOccurs="1" maxOccurs="1">
<xs:simpleType xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:restriction base="xs:token">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</element>
 
Here is the beginning of my xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:sakaifn="org.sakaiproject.metaobj.utils.xml.XsltFunctions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:osp="http://www.osportfolio.org/OspML" xmlns:xs="http://www.w3.org/2001/XMLSchema">

   
    <xsl:template match="formView">
        <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
            <head>
                <title>
                    Intr
                </title>
              </head>
            <body style="font-family:Calibri; font-size:11pt; background-color:#FFFFFF">
                <form method="post" onsubmit="a=1;">
                    <table border="0" style="text-align:left">
                        <tr style="background-color:#95B3D7">
                            <th span="2" style="font-family:Courier New; font-size:18pt">
                                Introduction Form Cust Rend
                            </th>
                        </tr>
                        <tr style="background-color:#FFFFFF">
                            <th span="2" style="background-color:#FFFFFF; height:5px">
                            </th>
                        </tr>
                        <tr style="background-color:#244061;color:#FFFFFF">
                            <th>
                                First Name
                            </th>
                            <th>
                                <xsl:value-of select=" BIOForm /FirstName"/>
                            </th>
                        </tr>
0
Comment
Question by:santaspores1
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:pfrancois
ID: 37729312
Note that I cannot change the xml/xsl methodology being used.
No need about changing the methodology, this is the best one.

The syntax of the select attribute of the instruction <xsl:value-of select=" BIOForm /FirstName"/> is not correct. What you have to enter here is a Xpath query.

The xml file you posted contains an opening <formView> tag, but also a corresponding closing </formView> tag. I suppose you will find between these tags some value you want to use as first name, but since you have cut the file, I can't figure out where you can find that value, and I can't help you to write the xpath query you need.

If you feel the xml file and the xsl file are too big, please attach these instead of posting only a (too little) part of it. I fear you do not understand fully the philosophy behind xsl/xml. I can help you to understand it better, but the elements you provided are not enough. Anyway, <xsl:value-of select="some-xpath-query"/> will not create an input field, but only output some string. It is even possible that the elements you need are not in the xml file itself, but in the file "file", i.e. referred by the xpath expression "/formView/formData/artifact/metaData/id/text()" or something similar.

Please give me more elements.
0
 
LVL 18

Expert Comment

by:zc2
ID: 37729466
Please take a look at the following sample, may be it will give you some ideas:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:sakaifn="org.sakaiproject.metaobj.utils.xml.XsltFunctions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:osp="http://www.osportfolio.org/OspML" xmlns:xs="http://www.w3.org/2001/XMLSchema">

   
    <xsl:template match="formView">
        <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
            <head>
                <title>
                    Introduction Form Cust Rend
                </title>
              </head>
            <body style="font-family:Calibri; font-size:11pt; background-color:#FFFFFF">
            	<xsl:apply-templates select="formData/artifact/schema/element"/>
            </body>
         </html>
                        
	</xsl:template>

	<xsl:template match="element[@name='BIOForm']">
        <form method="post" onsubmit="a=1;">
            <table border="0" style="text-align:left">
                <tr style="background-color:#95B3D7">
                    <th span="2" style="font-family:Courier New; font-size:18pt">
                        Introduction Form Cust Rend 
                    </th>
                </tr>
                <tr style="background-color:#FFFFFF">
                    <th span="2" style="background-color:#FFFFFF; height:5px">
                    </th>
                </tr>
                <xsl:apply-templates select="children/element"/>
            </table>
       </form>
 	</xsl:template>

	<xsl:template match="element">
        <tr style="background-color:#244061;color:#FFFFFF">
            <th>
                <xsl:value-of select="@name"/>
            </th>
            <th>
            	<input type="text" name="{@name}" value="" />
            </th>
        </tr>
	
 	</xsl:template>
	
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:santaspores1
ID: 37729541
zc2,

Thank you.  And you are quite right... I don't know what I am doing here and am just trying to cobble together first example.  I am going to attach three files.

(1) MyIntroForm.xsd.  This has my basic form elements.  This is a file I am uploading to a bit of software from sakai.  
(2) MyIntroFormPassthroughCreateResult.xml.  Supposedly this is the xml that automatically gets generated by the sakia software based on my MyIntroForm.xsd file.
(3) MyIntroForm_Create_CustRender5.xsl.  This is the wrapper file I am creating.  This needs to format the elements generated by MyIntroForm.xsd.
MyIntroForm.xsd
MyIntroFormPassthroughCreateResu.xml
MyIntroForm-Create-CustRender5.xsl
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 18

Accepted Solution

by:
zc2 earned 500 total points
ID: 37729695
I guess, you need to investigate the imported xsl "formCreate.xslt". I believe it contains all he templates you need to call to create the HTML forms.
Try to study the Sakai documentation (if you have one, search the internet if you don't), it should explain everything.
0
 
LVL 18

Expert Comment

by:zc2
ID: 37729708
here's a sample xslt I found
This link is  the Search page of the Sakai site
0
 

Author Comment

by:santaspores1
ID: 37729781
Thanks zc2,

Yes, formCreate.xslt does contain templates.  The thing is, I really don't want to import that file and use those templates... I just want to create an inline template of my own.  Shouldn't it be possible for my xsl to specify a template to use for formatting the FirstName filed that is defined in my xsd?

And again, thank you very much for the time that you have already invested in this question  - I really appreciate it.
0
 

Author Comment

by:santaspores1
ID: 37729879
Interesting... that sample you found is what I am currently using to navigate this issue.  But that person's "custom" render does almost no customization at all.

if I upload my xsd to sakai and do not upload a custom render file, then sakai will use formCreate.xslt and the result will look like [2012-02-24 MyIntroFormVer1.JPG].  Using my custom render xls I am getting [2012-03- CustomRender2_04.JPG] ... which looks good but does not include any data gathering elements.

I'll keep researching this, but if you have another moment to spare - thanks!
0
 
LVL 18

Expert Comment

by:zc2
ID: 37729911
I don't see the screen shots you were trying to show...
Anyway, I still think you need to figure out how to correct use the imported xslt template. I believe the guys who created it took care of everything.
You still can create the HTML form by yourself, but it could just generate the data which the server will not accept.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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