Avatar of santaspores1
santaspores1
Flag for United States of America asked on

xml / xsl / html Form

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>
XML

Avatar of undefined
Last Comment
zc2

8/22/2022 - Mon
Pierre François

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.
zc2

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

santaspores1

ASKER
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
zc2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zc2

here's a sample xslt I found
This link is  the Search page of the Sakai site
santaspores1

ASKER
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.
santaspores1

ASKER
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!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
zc2

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.