Solved

xml / xsl / html Form

Posted on 2012-03-16
8
484 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now