 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 15th, 2008, 10:24 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Saving XML thru href link using XSLT
Hello,
I looked at other topics but didn't find what I was looking for.
I'm sorry if its a repost.
This is what I'm trying to do...
Actually, I get an XML response and using XSLT I transform it into HTML. Now, my requirement demands me to have a hyperlink (eg: Save XML File) on the transformed HTML to allow the user to save that XML.
I don't know if it can be done on client side because hyperlink is on the transformed HTML and when the user clicks on the link where would he get the XML from? I think it has to be saved on the server side and then transferred to the client.
Is there a way that I could store the XML as soon as I get (before transformation) and when the hyperlink on HTML is clicked, just grab that XML from there?
Any help is really appreciated.
Thanks in advance.
|
|

June 16th, 2008, 02:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Where is the transformation applied? Client or Server?
Where do you want to save the file? Client or Server?
--
Joe ( Microsoft MVP - XML)
|
|

June 16th, 2008, 09:47 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for your prompt reply.
The transformation is applied on the server side and the XML is to be saved on the client eventually.
The hyperlink on the transformed HTML should allow the user to save the XML (that was transformed into HTML using XSLT) on his local drive.
Can you please suggest me the efficient way to do it?
|
|

June 17th, 2008, 01:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well saving to the client means that you're going to need the browser to have low security settings and is only really possible in an intranet scenario.
It also depends on whether you need to support IE and others or just IE. IE has the concept of XML data islands which allow arbitrary storage of XML within the page in an invisible manner. You can mimic these in Firefox etc. but that's extra work and they behave slightly differently.
So my plan would be one of the following: - Perform the server-side transformation, include in the output the raw XML, either as a data island or in a hidden textarea
- Include a link that has an onclick handler attached
- Include JavaScript in the page that saves the XML in the textarea to the local folder. As I said this is going to be difficult cross-browser
or: - Have the server-side transform as before but don't include the XML within the output
- Have a web service that returns an XML file given a unique-identifier. You might need to fiddle with the content-disposition header to get the browser to popup a save or open dialogue box rather than display the file
- Use the unique identifier in a link to kick off the XML download via the web service
--
Joe ( Microsoft MVP - XML)
|
|

June 17th, 2008, 11:16 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Awesome!!!
The 1st way seems very close to what I'm trying to do.
The only thing I'm think of now is how to get data island inside HTML.
Should I do it inside XSLT or the class where I received the XML response?
I know it might sound strange for you but the way I'm trying to implement it - got to think about it.
Anyways, thanks for the reply.
I'll post my updates.
|
|

June 18th, 2008, 03:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
I'd do it in the XSLT, you just need to <xsl:copy-of select="/" /> inside an element named xml. As I said this is IE only, if you want cross-browser use a hidden textarea.
--
Joe ( Microsoft MVP - XML)
|
|

June 18th, 2008, 01:58 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply.
Ok. This is for cross-browsers.
Method 1:
I got a textarea and filled it with the XML. And, I didn't hide the textarea because I wanted to see if I'm getting XML in it.
I used <xsl:copy-of select="/"/> as you suggested.
Now, I could get the XML in the textarea but all the namespaces in it are different than what actually are there in the real response. All the namespaces are replaced by ns1, ns2, etc. I think Apache Axis appends its own namespaces. Then, when I wanted to show this XML in the IE it gives me an error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Method 2:
I tried other way too:
Now, I added the textarea inside the servlet that is calling the transformation.
This textarea is added below the HTML that is generated. I could do what I wanted to do. This worked.
But my requirement wants me to have a link/button (which would trigger the servlet to download the XML) inside the HTML that is generated by XSLT.
Thanks again.
|
|

June 18th, 2008, 09:03 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I got it.
Just wanted to tell you.
Thanks a lot for your reply and support.
The hidden text areas worked.
But I need to think of this - what if a browser doesn't support CSS? Then my text areas will be visible.
Anyways,
thanks again.
|
|

June 19th, 2008, 02:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well you need to decide what browsers to support. Virtually all support basic CSS except for some mobile ones, would they be using your app?
--
Joe ( Microsoft MVP - XML)
|
|

June 19th, 2008, 08:33 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I don't think any mobile devices would access this.
[u]Question:</u>
I tried to extract a value(eg: employeeId) in XSLT so that I can use it as a name of the XML to save it. But I couldn't get the value. When I try to read the value it's always null.
I don't know if I'm framing the question correctly but this is what I could write.
I used <xsl:value-of select="xyz"/>
I even tried using a global variable <xsl:variable> yet no luck.
Any suggestions?
Thanks.
|
|
 |