954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

document.write() fucntion in XSL

I need to use document.write() in XSL. Will it work ? Please help

Rajicet
Newbie Poster
9 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

If you want to include Javascript into XSLT code, you have to define it within your processors "xsl:script" instruction.

There are plenty of examples out there of how this is done. Just google it.

For example.
http://www.xmlpitstop.com/discussions/displaypost.aspx?postid=1872

iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

If you should use inside an XSL file a script with document.write() and you cannot edit it(some counter for example), the next trick can help:

<script type="text/javascript">
// this is your script somewhere in HEAD
                        var document_write = '';
                        var obj = null;
                        document.write = function(str) {
                            document_write += str;
                        }
                        function begin(id) {
                            obj = document.getElementById(id);
                        }
                        function end() {
                            if(obj) {
                                obj.innerHTML = document_write;
                            }
                            document_write = '';
                        }

</script>

<!-- somewhere in BODY where you plan use another's script -->
<div id="some_id">
     <script type="text/javascript">begin('some_id');</script>
     <script type="text/javascript" src="http://www.other-domain.com/some_script_with_document_write.js"></script>
     <script type="text/javascript">end();</script>

</div>
Leksiq
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You