Solved

xml / xsl / html Form

Posted on 2012-03-16
8
529 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
[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
  • 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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