Solved

edit xml from the browser using xsl !!

Posted on 2004-09-27
7
297 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
[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
  • 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create XML 5 52
Cordova Camera plugin fails 2 165
Append data to an XML file 3 24
DTD and JAVA versions 1 28
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
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.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

735 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