Solved

edit xml from the browser using xsl !!

Posted on 2004-09-27
7
296 Views
Last Modified: 2013-11-19
Hi,
I am trying to do the following.
I have a simple xml file. An xsl transforms the values of the nodes into text boxes and shows it in as HTML. I have added the code for the xsl too at the bottom.
Now I want to allow editing the values in the text box using the browser. How do I do that ? Currently if I change the values in the text box, it shows the new values in the browser but even if I save this view as a new HTML file, I still get the same old values in the xml file. I want to be able make changes to the xml and save them. I know it can be done using ASP etc but i dont want to use ASP. The requirement is that I send such an xml file to some one by email who can open it and it should appear as a form to them which they can edit or fill out and save it and send it back to me over email as an attachment.
Thanks in advance.
mav.

XML File:EmpAttrTextBoxPull1.xml

<?xml version='1.0' encoding='utf-8' ?>
<?xml-stylesheet type="text/xsl" href="EmpAttrTextBoxPull1.xsl"?>
<employees>
      <employee>
            <employeename type="INPUT" desc="Employee Name" size="30">John Doe</employeename>
            <hourlyrate type="input" desc="Hourly Rate" size="12">5000</hourlyrate>
            <department type="input" desc="Department" size="20">ABC Inc</department>
            <nativelanguage type="input" desc="Spoken Language" size="25">English</nativelanguage>>
            <primarylanguage type="input" desc="Programming Language" size="25">All</primarylanguage>
      </employee>
</employees>


XSL file: EmpAttrTextBoxPull1.xsl

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html"/>
      
      <xsl:template match="/">

            
            <xsl:for-each select="/employees/employee">
                  <!-- The following for-each loop will iterate through all of the child elements
                 of employee -->
                  <xsl:for-each select="*">
                        <xsl:value-of select="@desc"/>
                        
                        <!-- Note: Curly braces are a shorthand for the value of an attribute -->
                        <xsl:element name="{@type}">

                              <!-- Set the Size of the textbox -->
                              <xsl:attribute name="size">
                                    <xsl:value-of select="@size"/>
                              </xsl:attribute>

                              <!-- Set the Size of the textbox -->
                              <xsl:attribute name="maxlength">
                                    <xsl:value-of select="@size"/>
                              </xsl:attribute>

                              <!-- Set the value of the text box -->
                              <xsl:attribute name="value">
                                    <xsl:value-of select="text()"/>
                              </xsl:attribute>
                              <br/>
                        </xsl:element>
                  </xsl:for-each>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>
0
Comment
Question by:maverick1611
  • 3
  • 3
7 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 12178595
You will have to some sort of form submital.  Include a <form> tag in the XSL and a submit button.  The action of the form is set for 'javaScript:SaveData()'

Write a saveData javascript that uses MSXML and takes the form data and writes it back to the XML document.
0
 

Author Comment

by:maverick1611
ID: 12182663
Hi,
thanks for the help. I've been able to put a submit button to call a javascript function from it.
The problem now is that I'm not able to write the javascript function to get the new values from the text boxes and save these values back to the xml file. could you please show me some sample code that does this.
thanks a lot .
mav.
0
 

Author Comment

by:maverick1611
ID: 12184285
Hi,
I tried a simple javascript to save the xml file, but it keeps giving me errors saying permission denied. I am wondering if it is even possible to save an xml file using javascript on the local machine since java script is client side and the browser wont let it have permission to write to client machines.

is there a work around for this . Please let me know.
Thanks,
mav
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 21

Expert Comment

by:MogalManic
ID: 12188283
That should work.  Could you send what you have so far?

0
 
LVL 21

Accepted Solution

by:
MogalManic earned 200 total points
ID: 12188397
I did a little research and it seems that it is a security risk to save an XML file using javascript.  You can try experimenting with the IE security settings.

Another option is to open up another window and instruct the user to open it up manually.  Maybe something like this:

function saveResults(xmlDoc)
{
   var docWindow=window.open("", "theSaveWindow", "");
   docWindow.document.write("<html><head><title>Save Data</title></head>");
   docWindow.document.write("<body><h1>Save the following text by selecting it and pasting it into notepad:</h1>");
   docWindow.document.write("<pre>"+xmlDoc.xml+"</pre>");
   docWindow.document.write("</body></html>");
   docWindow.focus();


}
0
 
LVL 7

Expert Comment

by:CleffedUp
ID: 12197153
I'm sorry to say that your requirements aren't feasible.  Any e-mail client worth anything is explicitly designed prohibit what you've described.  There's no avoiding developing an application to receive the form results in ASP/JSP/Whatever, which you include in the action field of your opening form tag.
0
 

Author Comment

by:maverick1611
ID: 12201275
Well thanks MogalManic,
I worked a bit on the security issues and now I use an ActiveXObject script to save the xml file on the client. The browser ofcourse gives me a warniong before it can run the script but it serves my purpose. one way of avoiding the warning messagfe would be to get a digital signature which i'll worry about later.
I'll give you 100 points none the less for pointing me in the right direction.
thanks.
mav
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkbox and ListView in Android Layout 4 77
Get the parent node - XMLTYPE 9 98
SQL XML ALL Nodes Compare in function 2 39
TSQL query to generate xml 4 46
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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. 
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

837 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