<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: I would like to use JavaScript in XSLT to generate XML, how?</title>
	<atom:link href="http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/</link>
	<description></description>
	<lastBuildDate>Tue, 06 Jul 2010 09:25:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Frank Fazzio</title>
		<link>http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/comment-page-1/#comment-1251</link>
		<dc:creator>Frank Fazzio</dc:creator>
		<pubDate>Fri, 29 Jan 2010 20:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/#comment-1251</guid>
		<description>The normal use for XSLT it not to generate XML, but &quot;transform&quot; XML into HTML for presentation.

You can imbed &lt;script&gt; in your XSLT, and using &quot;document.writeln()&quot; functions create and HTML objects you want.

This is SAMPLE.XML...

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;sample.xsl&quot;?&gt;
&lt;root&gt;
&lt;thing id=&quot;0&quot;&gt;
&lt;data&gt;zero&lt;/data&gt;
&lt;/thing&gt;
&lt;thing id=&quot;1&quot;&gt;
&lt;data&gt;one&lt;/data&gt;
&lt;/thing&gt;
&lt;thing id=&quot;2&quot;&gt;
&lt;data&gt;two&lt;/data&gt;
&lt;/thing&gt;
&lt;thing id=&quot;3&quot;&gt;
&lt;data&gt;three&lt;/data&gt;
&lt;/thing&gt;
&lt;/root&gt;

This is SAMPLE.XSL...

&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
&lt;xsl:template match=&quot;/&quot;&gt;
 &lt;html&gt;
&lt;script&gt;
document.writeln(&quot;&lt;h1&gt;This is a test&lt;/h1&gt;&quot;);
&lt;/script&gt;
 &lt;body&gt;
   &lt;table border=&quot;1&quot;&gt;
     &lt;tr bgcolor=&quot;#c0c0c0&quot;&gt;
       &lt;th&gt;Id&lt;/th&gt;
       &lt;th&gt;Data&lt;/th&gt;
     &lt;/tr&gt;
    &lt;xsl:for-each select=&quot;root/thing&quot;&gt;
    &lt;xsl:if test=&quot;@id&gt;&#039;0&#039;&quot;&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select=&quot;@id&quot;/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select=&quot;data&quot;/&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/xsl:if&gt;
    &lt;/xsl:for-each&gt;
   &lt;/table&gt;
 &lt;/body&gt;
 &lt;/html&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</description>
		<content:encoded><![CDATA[<p>The normal use for XSLT it not to generate XML, but &quot;transform&quot; XML into HTML for presentation.</p>
<p>You can imbed &lt;script&gt; in your XSLT, and using &quot;document.writeln()&quot; functions create and HTML objects you want.</p>
<p>This is SAMPLE.XML&#8230;</p>
<p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;sample.xsl&quot;?&gt;<br />
&lt;root&gt;<br />
&lt;thing id=&quot;0&quot;&gt;<br />
&lt;data&gt;zero&lt;/data&gt;<br />
&lt;/thing&gt;<br />
&lt;thing id=&quot;1&quot;&gt;<br />
&lt;data&gt;one&lt;/data&gt;<br />
&lt;/thing&gt;<br />
&lt;thing id=&quot;2&quot;&gt;<br />
&lt;data&gt;two&lt;/data&gt;<br />
&lt;/thing&gt;<br />
&lt;thing id=&quot;3&quot;&gt;<br />
&lt;data&gt;three&lt;/data&gt;<br />
&lt;/thing&gt;<br />
&lt;/root&gt;</p>
<p>This is SAMPLE.XSL&#8230;</p>
<p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;<br />
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;<br />
&lt;xsl:template match=&quot;/&quot;&gt;<br />
 &lt;html&gt;<br />
&lt;script&gt;<br />
document.writeln(&quot;&lt;h1&gt;This is a test&lt;/h1&gt;&quot;);<br />
&lt;/script&gt;<br />
 &lt;body&gt;<br />
   &lt;table border=&quot;1&quot;&gt;<br />
     &lt;tr bgcolor=&quot;#c0c0c0&quot;&gt;<br />
       &lt;th&gt;Id&lt;/th&gt;<br />
       &lt;th&gt;Data&lt;/th&gt;<br />
     &lt;/tr&gt;<br />
    &lt;xsl:for-each select=&quot;root/thing&quot;&gt;<br />
    &lt;xsl:if test=&quot;@id&gt;&#8217;0&#8242;&quot;&gt;<br />
    &lt;tr&gt;<br />
      &lt;td&gt;&lt;xsl:value-of select=&quot;@id&quot;/&gt;&lt;/td&gt;<br />
      &lt;td&gt;&lt;xsl:value-of select=&quot;data&quot;/&gt;&lt;/td&gt;<br />
    &lt;/tr&gt;<br />
    &lt;/xsl:if&gt;<br />
    &lt;/xsl:for-each&gt;<br />
   &lt;/table&gt;<br />
 &lt;/body&gt;<br />
 &lt;/html&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris_thomas_morgan</title>
		<link>http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/comment-page-1/#comment-1252</link>
		<dc:creator>chris_thomas_morgan</dc:creator>
		<pubDate>Fri, 29 Jan 2010 20:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnxmlws.com/i-would-like-to-use-javascript-in-xslt-to-generate-xml-how/#comment-1252</guid>
		<description>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&#039;t.  You can do just about anything within XSLT that you&#039;d be able to accomplish through JavaScript, but it&#039;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&#039;s particularly hard to set and manipulate global variables as you transform XML with XSLT. 

Good luck.</description>
		<content:encoded><![CDATA[<p>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&#8217;t.  You can do just about anything within XSLT that you&#8217;d be able to accomplish through JavaScript, but it&#8217;s a different way of thinking about it.  </p>
<p>I would recommend looking into XSLT named templates (<a href="http://www.devx.com/getHelpOn/10MinuteSolution/20363" rel="nofollow">http://www.devx.com/getHelpOn/10MinuteSolution/20363</a>), which are somewhat analogous to javascript functions.  </p>
<p>Keep in mind that scope and context &#8211; where you are in the processing of a given node and what data is available to you &#8211; is very important.   It&#8217;s particularly hard to set and manipulate global variables as you transform XML with XSLT. </p>
<p>Good luck.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
