Skip to content

I would like to use JavaScript in XSLT to generate XML, how?

I would like to use JavaScript in XSLT to generate XML, i want small example to illustrate this.

46 Comments

  1. Frank Fazzio wrote:

    The normal use for XSLT it not to generate XML, but "transform" XML into HTML for presentation.

    You can imbed <script> in your XSLT, and using "document.writeln()" functions create and HTML objects you want.

    This is SAMPLE.XML…

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="sample.xsl"?>
    <root>
    <thing id="0">
    <data>zero</data>
    </thing>
    <thing id="1">
    <data>one</data>
    </thing>
    <thing id="2">
    <data>two</data>
    </thing>
    <thing id="3">
    <data>three</data>
    </thing>
    </root>

    This is SAMPLE.XSL…

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <script>
    document.writeln("<h1>This is a test</h1>");
    </script>
    <body>
    <table border="1">
    <tr bgcolor="#c0c0c0">
    <th>Id</th>
    <th>Data</th>
    </tr>
    <xsl:for-each select="root/thing">
    <xsl:if test="@id>’0′">
    <tr>
    <td><xsl:value-of select="@id"/></td>
    <td><xsl:value-of select="data"/></td>
    </tr>
    </xsl:if>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Friday, January 29, 2010 at 3:24 pm | Permalink
  2. chris_thomas_morgan wrote:

    Past versions of the Microsoft XML processor (MSXML 2.6 and below) supported the use of jscript functions within XSLT to perform various subroutines. However, newer versions and other XML APIs don’t. You can do just about anything within XSLT that you’d be able to accomplish through JavaScript, but it’s a different way of thinking about it.

    I would recommend looking into XSLT named templates (http://www.devx.com/getHelpOn/10MinuteSolution/20363), which are somewhat analogous to javascript functions.

    Keep in mind that scope and context – where you are in the processing of a given node and what data is available to you – is very important. It’s particularly hard to set and manipulate global variables as you transform XML with XSLT.

    Good luck.

    Friday, January 29, 2010 at 3:24 pm | Permalink
  3. Im an enormous fan already, gentleman. Youve completed a wonderful job ensuring folks recognize wherever youre coming from. And allow me to let you know, I get it. Fantastic things and I cant wait around to study far more of your weblogs. What youve got to say is important and wants to become read.

    Friday, November 4, 2011 at 3:52 am | Permalink
  4. Useful data and outstanding design you obtained here! I would want to thanks for sharing your ideas and time into the stuff you post!! Thumbs up

    Friday, November 4, 2011 at 12:03 pm | Permalink
  5. Nice blog , I am just learning some weblogs to make use of for my franchise advertising and marketing blog. finest needs, James

    Tuesday, November 8, 2011 at 1:46 pm | Permalink
  6. The next time I study a blog, I hope that it doesnt disappoint me as considerably as this one. I imply, I realize it was my option to read, but I actually believed youd have some thing fascinating to say. All I hear is actually a bunch of whining about one thing that you simply could fix in the event you werent as well hectic looking for attention.

    Tuesday, November 8, 2011 at 3:25 pm | Permalink
  7. One of the more extraordinary weblogs Ive noticed. Thanks so a lot for maintaining the internet classy to get a change. Youve got style, class, bravado. I imply it. Remember to keep it up simply because with out the internet is absolutely lacking in intelligence.

    Wednesday, November 9, 2011 at 10:50 pm | Permalink
  8. This is actually a very exclusive subject material. It is very instructive and also you also have needless to say accomplished your preparation top up to producing this article. I’ve to revisit and study your potential content.

    Thursday, November 10, 2011 at 4:24 am | Permalink
  9. This will be the best weblog for everyone who hopes to know about this topic. You recognize so considerably its nearly difficult to argue with you (not that I genuinely would want…HaHa). You definitely put a brand new spin on a subject thats been published about for yrs. Great stuff, just excellent!

    Thursday, November 10, 2011 at 10:32 am | Permalink
  10. Definitely accurate, i completely agree with your write-up and have shared all of your ideas with my friends. Quite excellent function indeed!

    Sunday, November 13, 2011 at 9:43 am | Permalink
  11. Im not 100% on this, but I do like the concept. High-quality read here

    Monday, November 14, 2011 at 12:32 pm | Permalink
  12. Clay Janssen wrote:

    How did you receive to become this very good? Its incredible to find an individual place so a lot enthusiasm into a topic. Im glad I stumbled on this. Im glad I took time to read on past the first paragraph. Youve obtained so significantly to say, so much to offer. I hope individuals realise this and look into your page.

    Monday, November 14, 2011 at 4:49 pm | Permalink
  13. rod mill wrote:

    Im curious if you ever have problems with what people post? Honestly the internet used to be like a different place, although it seems to be changing for the better. What do you think?

    Wednesday, November 16, 2011 at 12:26 am | Permalink
  14. This is the excellent weblog for anyone who wants to know about this subject. You recognize so a lot its practically hard to argue with you (not that I definitely would want…HaHa). You without a doubt place a brand new spin on the subject thats been created about for yrs. Excellent things, just excellent!

    Friday, November 18, 2011 at 7:38 am | Permalink
  15. Maud Janecka wrote:

    Im an enormous enthusiast currently, gentleman. Youve accomplished a perfect task ensuring that people understand where youre coming from. And allow me to tell you, I get it. Wonderful things and I cant wait to read more of your weblogs. What youve got to say is essential and requirements to become study.

    Sunday, November 20, 2011 at 9:59 pm | Permalink
  16. You did a great job.

    Wednesday, November 23, 2011 at 11:22 pm | Permalink
  17. I like the valuable information you provide in your articles. I’ll bookmark your blog and check again here frequently. I am quite certain I’ll learn lots of new stuff right here! Best of luck for the next!

    Thursday, November 24, 2011 at 3:29 am | Permalink
  18. Interesting information provided, have send your url to a few others

    Thursday, November 24, 2011 at 11:51 am | Permalink
  19. Salute! You just have to take a look my page indirmeden film izle!

    Thursday, November 24, 2011 at 2:58 pm | Permalink
  20. Thank you for another wonderful article. Where else could anybody get that kind of information and facts in such a perfect way of writing? I have a presentation next week, and I am on the appear for these facts.

    Sunday, November 27, 2011 at 10:44 am | Permalink
  21. I found this an informative and interesting article. I think it is very readable and knowledgeable, happy to see some people still have interest in this. I would like to thank you for the work you have made in writing this article. I am wish the same best work from you in the future as well kind regards

    Sunday, November 27, 2011 at 4:08 pm | Permalink
  22. r4ds wrote:

    How is it that just anyone can publish a weblog and get as popular as this? Its not like youve said anything incredibly impressive more like youve painted a fairly picture more than an issue that you know nothing about! I dont want to sound mean, here. But do you actually think that you can get away with adding some pretty pictures and not definitely say something?

    Monday, November 28, 2011 at 1:22 am | Permalink
  23. Kellye Mowen wrote:

    Good thinking. Wondering what you think of its implication on society as a whole though? There are times when things like this begin to have global expansion and frustration. Ill check back to see what you have to say.

    Monday, November 28, 2011 at 5:47 am | Permalink
  24. I totally agree. What are your criteria? Lately Ive been following Damon Vickers, a finacial luminary from Seattle. If you havnt read his book about one global currency, you should get your hands on a copy. I believe that people dont really know the magnitude of the situation we face today. To have a top strategist like Damon Vickers, who called the market plummet in both 2000 and 2008, publicly express the fears of many of the approach of a one world government is fantastic. At any rate, cool list and can’t wait ‘til the next article

    Monday, November 28, 2011 at 7:02 pm | Permalink
  25. r4ds wrote:

    I like your blog.

    Tuesday, November 29, 2011 at 1:20 am | Permalink
  26. Always have to post a comment, I cant help it ! Thanks Sarah

    Tuesday, November 29, 2011 at 4:42 am | Permalink
  27. My sister saved this web publication for me and I have been reading through it for the past couple hrs. This is really going to aid me and my friends for our class project. By the way, I like the way you write.

    Wednesday, November 30, 2011 at 3:03 am | Permalink
  28. This really is an outstanding article, I was wondering whether I might use this write-up on my personal internet site, I will hyperlink it back to your website though. If this sounds like a problem please let me know and I will take it down at once

    Thursday, December 1, 2011 at 10:32 am | Permalink
  29. Truly good appreciate it, I’m sure your trusty audience could possibly want considerably more details like that continue the decent effort.

    Thursday, December 1, 2011 at 12:49 pm | Permalink
  30. I have learn some good stuff right here. Certainly worth bookmarking for revisiting. I surprise how a lot work you set to generate this sort of fantastic informative internet site.

    Saturday, December 3, 2011 at 6:09 pm | Permalink
  31. pipe elbow wrote:

    I genuinely enjoy looking through on this web site , it has great content . Houston Tantra – Tantric Sexuality 3131 Memorial Ct. Suite 301 Houston, TX 77007 (832) 615 6458

    Monday, December 5, 2011 at 3:35 am | Permalink
  32. headscarf wrote:

    I really like what you posted. I really agree with what you wrote.

    Monday, December 5, 2011 at 11:20 am | Permalink
  33. I believe I should mind my manners.

    Monday, December 5, 2011 at 11:35 pm | Permalink
  34. rod mill wrote:

    Thank you, great post! Just the thing I needed to know.

    Tuesday, December 6, 2011 at 2:28 am | Permalink
  35. Ruben Tanks wrote:

    I just added this website to my favorites. I really like reading your posts. Tyvm!

    Tuesday, December 6, 2011 at 12:39 pm | Permalink
  36. Leona Shiloh wrote:

    Thnx so much for this! I havent been this thrilled by a blog post for a long time! You have got it, whatever that means in blogging. Anyway, Youre definitely somebody that has something to say that people should hear. Keep up the outstanding work. Keep on inspiring the people!

    Tuesday, December 6, 2011 at 11:14 pm | Permalink
  37. Theo Monica wrote:

    I really enjoyed reading your website, I found it in Yahoo. I recently came acrossa reallyinteresting pdf finder type site, its a pdf search engine and I think it is very interesting for people who like reading pdfs

    Tuesday, December 6, 2011 at 11:21 pm | Permalink
  38. Zada Nori wrote:

    AC Compressor sr gsr gsrg

    Wednesday, December 7, 2011 at 3:55 pm | Permalink
  39. created impulse spending by companions.

    Thursday, December 8, 2011 at 2:56 pm | Permalink
  40. I truly appreciate this article post.Much thanks again. Really Great.

    Thursday, December 8, 2011 at 9:18 pm | Permalink
  41. Thankyou for sharing the information with us.

    Thursday, December 8, 2011 at 9:46 pm | Permalink
  42. focalprice wrote:

    A splendid article, I just given this onto a colleague who was doing a little analysis on this. And he in fact purchased me lunch because I found it for him :) . So let me rephrase that: Thanks for the treat! But yeah Thankx for taking the time to talk about this, I feel strongly about it and enjoy learning more on this topic. If possible, as you become expertise, would you mind updating your blog with more info? It is extremely helpful for me. Two thumb up for this article!

    Thursday, December 8, 2011 at 11:58 pm | Permalink
  43. is a surprisingly transparent way to gain access to more types of.

    Monday, December 12, 2011 at 9:47 am | Permalink
  44. almost all of what youre It must be quite a lot of work to keep your blog so nice and neat! Im sure all of us readers appreciate your efforts as much as me!

    Monday, December 12, 2011 at 2:04 pm | Permalink
  45. Randy Ady wrote:

    Hey this is a good post . Can I use a portion of it on my page? I would of course link to your site so people could view the complete article if they wanted to. Thanks either way.

    Wednesday, December 14, 2011 at 5:07 am | Permalink
  46. Relying on your instanct is tough for most of us. Many of us develop this ability over the course of our life. It doesnt really just happen if you know what I mean.

    Wednesday, December 14, 2011 at 9:43 pm | Permalink

Post a Comment

Your email is never published nor shared.