Solved

edit xml from the browser using xsl !!

Posted on 2004-09-27
7
287 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

757 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

22 Experts available now in Live!

Get 1:1 Help Now