Solved

xml / xsl / html Form

Posted on 2012-03-16
8
507 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get last 10 digits of an xsl value-of field 7 59
How can I assign SimpleXMLElements to variables? 5 61
XSLT XML 4 19
Help needed with Powershell  XML to MySQL 5 37
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

16 Experts available now in Live!

Get 1:1 Help Now