Solved

edit xml from the browser using xsl !!

Posted on 2004-09-27
7
289 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET XML Processing a XMLNodeList with Namespace 16 67
MVC and Angular 2 91
Create associate webpages / websites 3 67
Windows Tool to Build Android and iOS App 3 54
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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 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

15 Experts available now in Live!

Get 1:1 Help Now