<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WebProNews &#187; XSL</title>
	<atom:link href="http://www.webpronews.com/tag/xsl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.webpronews.com</link>
	<description>Breaking News in Tech, Search, Social, &#38; Business</description>
	<lastBuildDate>Sun, 12 Feb 2012 16:37:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What is DTD?</title>
		<link>http://www.webpronews.com/what-is-dtd-2006-08</link>
		<comments>http://www.webpronews.com/what-is-dtd-2006-08#comments</comments>
		<pubDate>Mon, 14 Aug 2006 19:37:36 +0000</pubDate>
		<dc:creator>Jim Pretin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[DTD]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=30894</guid>
		<description><![CDATA[I have been designing websites since 1996. In the beginning, it was so easy.
]]></description>
			<content:encoded><![CDATA[<p>I have been designing websites since 1996. In the beginning, it was so easy.</p>
<p>Someone called me with a project, they sent me the content for their website, which I would then upload to Microsoft Frontpage or a text editor, insert some HTML tags for formatting and some graphics to make the site colorful, and the job was finished.</p>
<p>The wireless revolution changed everything. Almost every electronic device now comes equipped with access to the web and email. Palm tops, laptops, cell phones, even computer screens installed in automobiles are now connected to the internet. The web browsers and operating systems installed on these wireless devices are often very different from what is installed on an ordinary desktop PC. Many elements of the HTML programming language are not compatible with some of these wireless platforms. As a result, web design has completely changed. Cross-platform programming languages and specifications have been created so that websites can be viewed on any PC or wireless gadget.</p>
<p>These new innovations include languages such as XML, XHTML, and XSL, to name a few. XML was probably the most important of all of them, because it allowed a programmer to define data without telling the browser how to display it. The problem with HTML is that it defines data and also tells the browser how to display it. XML is different in that it merely defines the data, and allows the browser to display the data as it sees fit. Languages such as XHTML and XSL were developed in order to convert XML documents into web pages that could be displayed in a manner that was compatible with all browsers.</p>
<p>Now that you have some background on how and why web design has changed, you are now ready to learn about Document Type Definition (DTD). DTD is a tool that enables a programmer to define the format to be used for the data in an XML document. Remember, XML does not tell the web browser how to display or format content. DTD helps to establish the format. </p>
<p>An XML document consists of five different components. There are elements, attributes, entities, PCDATA, and CDATA. We will start with elements. Elements of XML are the tags. There are no predefined tags with XML; you can create your own tags. HTML does not work this way. All of the tags used in HTML are predefined, such as the paragraph tag and the body tag. Attributes provide additional information about the tags, such as the source file for an image, or the alignment to be used for a paragraph. Entities are variables that define commonly used text, such as the no-breaking-space entity. PCDATA is used to mark data that is to be parsed or separated into more easily processed components and to cause tags within that data to be interpreted as markup instead of as ordinary data. CDATA is used to mark data that is not to be parsed and to cause the tags within that portion of the text to not be treated as markup. As an aside, markup is any language that defines how certain text is to be displayed or structured.</p>
<p>For novice programmers, DTD is a little hard to get used to. I recommend that you search for tutorials on any major search engine, or perhaps find some courses offline at a local college or computer science institute. If you have never studied XML, XHTML, or XSL before, then you should find a broad-based curriculum of computer programming courses that teach you all of these languages so that you can learn to incorporate them together when you create web sites.</p>
<p>Learning to use these new specifications and languages is essential for any web designer. With so many people using cell phones and other wireless devices to surf the net, by creating your web sites exclusively with HTML you run the risk of your site being invisible to a wireless internet user. Designing web sites that are cross-platform compatible is a must in the wireless age we now inhabit.</p>
<p>Tag: </p>
<p>Add to <a   href="http://del.icio.us/post"onclick="window.open('http://del.icio.us/post?v=4&#038;partner=wpn&#038;noui&#038;jump=close&#038;url='+encodeURICo  mponent(location.href)+'&#038;title ='+encodeURIComponent(document.title),'delicious','toolbar=no,width=700,height=400'); return   false;" CLASS="printMailTop"><img src=http://images1.ientrymail.com/webpronews/delicious-pic.png border=0> Del.icio.us</a> |   <a       href="javascript:voidwindow.open('http://digg.com/submit?phase=2&#038;url='+encodeURIComponent(window.location.href)+'&#038;ei=UTF-8','  popup','width=520px,height=420px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=50',0)"><img   src=http://images1.ientrymail.com/webpronews/digg-pic.png border=0> Digg</a>  | <a href="javascript:void   window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(document.title)+'&#038;u='+encodeURICompo  nent(window.location.href),'popup','width=520px,height=420px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=50',0)   "><img src=http://images1.ientrymail.com/webpronews/yahoo-pic.png border=0> Yahoo! My Web</a> | <a   href="javascript:location.href='http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(document.location.href)+'&#038;t='+encodeUR  IComponent(document.title)+' '"><img src=http://images1.ientrymail.com/webpronews/furl-pic.png border=0> Furl</a></p>
<p>Bookmark WebProNews: <a href=http://www.webpronews.com><img src=http://images.ientrymail.com/webpronews/wpn-readit.jpg border=0></a><br />
<script language=JavaScript src="http://aj.600z.com/aj/1095/0/vj?z=1&#038;dim=1088&#038;pos=15"></script></p>
<p>Jim Pretin is the owner of http://www.forms4free.com, a service that helps programmers make email forms.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/what-is-dtd-2006-08/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is XSL?</title>
		<link>http://www.webpronews.com/what-is-xsl-2006-08</link>
		<comments>http://www.webpronews.com/what-is-xsl-2006-08#comments</comments>
		<pubDate>Wed, 02 Aug 2006 15:28:22 +0000</pubDate>
		<dc:creator>Jim Pretin</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=30688</guid>
		<description><![CDATA[Remember the good old days, when the internet consisted of nothing more than a few simple websites formatted in basic HTML? Web design was so easy.
]]></description>
			<content:encoded><![CDATA[<p>Remember the good old days, when the internet consisted of nothing more than a few simple websites formatted in basic HTML? Web design was so easy.</p>
<p>You could just slap some graphics and text into a file, insert some HTML tags into the document to tell the web browser how the text should appear and what the structure of the page should be, and presto, the job was finished. </p>
<p>As time went on, web design became more arduous. Businesses, especially ecommerce businesses that depended upon their internet storefronts to make a living, began to present web designers with near impossible projects that were too difficult to complete with basic HTML. The data being used and the designs that were being implemented for websites required more versatile programming specifications. </p>
<p>What resulted was the evolution of new specifications and languages for creating web sites. Languages and sub-languages such as XML, XHTML, style sheets, and a host of other more refined and yet more flexible specifications were spliced together to take web design to a new level. </p>
<p>One of the most important languages that came to be in recent years is called XSL. What is XSL, you ask? Well, to totally understand what XSL is and why it is so important, you must first understand XML. </p>
<p>XML is a markup language just like HTML. XML was created to deal with the fact that HTML was limited in that all of its tags were predefined and it displayed data a certain way. XML has no predefined tags, and does not tell a computer how data should appear, it merely defines the data. So, using XML, a web designer can define all sorts of data and more effectively transmit this data to web browsers installed on different platforms that run on a variety of electronic gadgets such as cell phones and other handheld devices that now come equipped with internet access. In a nutshell, XML was created to deal with the fact that so many different electronic products now come equipped with access to the internet and email. These new devices run on platforms that do not always display data properly if it is coded using HTML. XML fixed this situation by simply defining data and not forcing the web browser to display it a certain way, because an XML file is merely a simple text file. </p>
<p>So, again you ask, what is XSL and why is it important? XSL stands for Extensible Stylesheet Language. You have probably heard of Cascading Style Sheets (CSS). CSS is a style sheet language that evolved to make it easier for web designers to create a style for an HTML web page. Because XML is now so important, and because XML tags, as explained in the previous paragraph, do not tell the web browser how data should appear, a stylesheet language that was XML-based became a necessity. </p>
<p>XSL consists of 3 components. The first and most important component is XSLT. XSLT transforms an XML document into another XML document that can actually be understood and displayed by a computer. It accomplishes this by transforming most of the document into XHTML, which is a more versatile, cross-platform, XML-based version of HTML. </p>
<p>The second part of XSL is XPath. XPath is used as the navigator for XSL. XSL uses XPath to find parts of the source document that should match a certain predefined template. When XPath finds what it is looking for, then XSLT takes over and performs a transformation, turning the source document into what is called the result document. </p>
<p>The final part of XSL is known as XSL-FO. This component is for the final formatting. Once XPath has searched through the source document and used XSLT to transform the source document into the result document, the document then needs to be formatted so that the web browser will be able to present the document with the proper layout and structure. Simply put, XSL-FO is the part of XSL that produces the final output. </p>
<p>There are all sorts of helpful online tutorials for programmers and web designers to begin to learn how to use and implement XSL, but it would probably be best take a course in XSL at a local institute, college, or wherever you can find one. If web design is your career, learning it is not an option, it is a necessity, as most web browsers are now capable of understanding XSL. Since the advent of wireless internet access, everything from cell phones, to palm tops, to computer screens in automobiles can be used to connect to the internet. These different devices run on different platforms and have different web browsers that cannot properly display many elements of the HTML programming language. As a result, it is critical for all web designers to be able to create web pages using cross-platform specifications with the adaptability provided by XSL.</p>
<p>Tag: </p>
<p>Add to <a   href="http://del.icio.us/post"onclick="window.open('http://del.icio.us/post?v=4&#038;partner=wpn&#038;noui&#038;jump=close&#038;url='+encodeURICo  mponent(location.href)+'&#038;title ='+encodeURIComponent(document.title),'delicious','toolbar=no,width=700,height=400'); return   false;" CLASS="printMailTop"><img src=http://images1.ientrymail.com/webpronews/delicious-pic.png border=0> Del.icio.us</a> |   <a       href="javascript:voidwindow.open('http://digg.com/submit?phase=2&#038;url='+encodeURIComponent(window.location.href)+'&#038;ei=UTF-8','  popup','width=520px,height=420px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=50',0)"><img   src=http://images1.ientrymail.com/webpronews/digg-pic.png border=0> Digg</a>  | <a href="javascript:void   window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(document.title)+'&#038;u='+encodeURICompo  nent(window.location.href),'popup','width=520px,height=420px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=50',0)   "><img src=http://images1.ientrymail.com/webpronews/yahoo-pic.png border=0> Yahoo! My Web</a> | <a   href="javascript:location.href='http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(document.location.href)+'&#038;t='+encodeUR  IComponent(document.title)+' '"><img src=http://images1.ientrymail.com/webpronews/furl-pic.png border=0> Furl</a></p>
<p>Bookmark WebProNews: <a href=http://www.webpronews.com><img src=http://images.ientrymail.com/webpronews/wpn-readit.jpg border=0></a><br />
<script language=JavaScript src="http://aj.600z.com/aj/1095/0/vj?z=1&#038;dim=1088&#038;pos=15"></script></p>
<p>Jim Pretin is the owner of http://www.forms4free.com, a service that helps programmers make email forms.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/what-is-xsl-2006-08/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Strengths and Weaknesses with DOM, ASP and XSL</title>
		<link>http://www.webpronews.com/xml-strengths-and-weaknesses-with-dom-asp-and-xsl-2004-11</link>
		<comments>http://www.webpronews.com/xml-strengths-and-weaknesses-with-dom-asp-and-xsl-2004-11#comments</comments>
		<pubDate>Fri, 19 Nov 2004 21:05:33 +0000</pubDate>
		<dc:creator>Nakul Goyal</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=12862</guid>
		<description><![CDATA[Since the inception of XML, many developers have wondered why we need XML...
]]></description>
			<content:encoded><![CDATA[<p>Since the inception of XML, many developers have wondered why we need XML&#8230;</p>
<p>How is it better than HTML and what does it do? For starters, XML is far more powerful than HTML, and the power resides in the &#8220;X&#8221; in XML (which stands for extensible). Rather than providing a set of pre-defined tags (as in the case of HTML), XML specifies the standards with which you can define your own markup languages with their own sets of tags. XML is therefore a meta-markup language, allowing you to define an infinite number of markup languages based upon the standards defined by XML. </p>
<p>XML was created so that richly structured documents could be used over the web. The only viable alternatives, HTML and SGML, are not practical for this purpose. XML allows you to define all sorts of tags with all sorts of rules, such as tags representing business rules or tags representing data description or data relationships. </p>
<p>In this article we&#8217;re going to take a look at some of the terminology that comes with using XML and its related technologies, as well as how to create and transform XML documents with XSL using Microsoft&#8217;s MSXML parser. To test the code samples shown in this article you should be running Windows NT/2000/XP with IIS installed. You should also have SQL server 2000 installed on the same machine.</p>
<p><b>XML Definitions</b></p>
<p>As with any technology, XML has its own acronym-riddled lingo. Some of the important acronyms include: </p>
<li><b>DTD:</b> In XML, the definition of a valid markup is handled by a Document Type Definition (DTD), which communicates the structure of the markup language. The DTD specifies the validity of each tag. </li>
<p><b>XSL: </b>The Extensible Style Language (XSL) is the style language for XML that allows us to transform XML nodes using a set of patterns and templates. </p>
<li><b>XML Pointer Language (XPointer) and XML Linking Language (XLink):</b> These two technologies define a standard way to represent links between resources. In addition to simple links like HTML&#8217;s &lt;a&gt; tag, XML has mechanisms for linking between multiple resources and linking between read-only resources. XPointer describes how to address a resource whereas XLink describes how to associate two or more resources. </li>
<li><b>XML Flow Architecture:</b> XML offers a three-tier architecture. It can be generated from existing databases that employ a 3-tier model themselves. We can maintain business rules separately.</li>
<p><b>Why XML Should Be Used? </b></p>
<p>Using XML provides us as developers with a number of benefits. Some of the most obvious benefits include: </p>
<li>Authors and providers can design their documents using XML, instead of being stuck with HTML. They can be explicitly tailored for an audience, so the cumbersome problems with HTML are theoretically eliminated; therefore both authors and designers are free to invent their own markup elements. </li>
<li>Information can be richer and is easier to access and manipulate because the hypertext linking abilities of XML are much more advanced than those found in HTML. </li>
<li>XML can provide more (and improved) facilities for browser presentation and performance.</li>
<p>XML compresses exceedingly well. Since data compression algorithms operate on the concept of maximizing the entropy of a given input stream, it stands to reason that a highly ordered input stream consisting of regular, repeating tag sequences will compress exceedingly well&#8230; much better than standard text which contains generally far less order thus resulting in a decrease in performance. </p>
<p><a name="xml"></a><b>Weaknesses of XML </b></p>
<p>XML is obviously not a cure-all language free of any disadvantages&#8230; otherwise we would be using XML to markup/represent all of our data, and nothing else! There are of course some drawbacks and weaknesses of XML, namely: </p>
<li>XML markup can be incredibly verbose, depending on the vocabulary in question. </li>
<li>All the pieces of the XML puzzle aren&#8217;t yet in place, certainly not from a standards-compliant viewpoint anyhow. We&#8217;ve got both XSL and XSLT, however they are not fully developed yet. </li>
<li>There are still some problems with Microsoft&#8217;s XML Parser. </li>
<li>XML Hypertext Transfer Protocol (XML-HTTP) still has some minute problems.</li>
<p><b>Performance of XML </b></p>
<p>When you&#8217;re designing an XML-based Web application, what kind of performance hit do you expect to put on your web server? It&#8217;s hard to generalize because there are so many variables (such as the size of the XML document, the amount of script code required to process the document, the amount of output generated, etc) to take into consideration, however the following list shows the major variables that can affect the performance of parsing XML: </p>
<li>The Kind of XML Data being parsed. </li>
<li>The ratio of tags to text. </li>
<li>The ratio of attributes to elements. </li>
<li>The amount of discarded white space in the document.</li>
<p><b>XML and DOM</b></p>
<p>Microsoft have provided us with the MSXML parser, which exposes an XML document in the form of a DOM (Document Object Model). With the XML DOM, you can load and parse XML files, gather information about those files, navigate through and manipulate those files. To learn more about the details of the XML DOM, please refer to this site. </p>
<p>Now that we&#8217;ve discussed the reasons for using XML, it&#8217;s time to look at some source code. We will examine some ASP scripts that create and display XML data. We&#8217;re going to create an XML file using both static data and data from a database using ADO. The DOM methods createNode and appendChild, as well as the text property are used to construct an in-memory XML tree. </p>
<p><b>XML with ASP </b></p>
<p>The following example illustrates how to create an XML tree (in memory) and then persist is to disk using the save method: </p>
<p><code>&lt;% </p>
<p>Dim xmldoc<br />
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM") </p>
<p>' Check to see if document has data. If it does, don't build it<br />
If (xmldoc.childNodes.length = 0) Then </p>
<p>' Build the XML document<br />
Set root = xmldoc.createNode("element", "Hi-Tech", "")<br />
xmldoc.appendChild (root) </p>
<p>Set onode = xmldoc.createNode("element", "Employee", "")<br />
onode.Text = "Gurpreet Singh" </p>
<p>xmldoc.documentElement.appendChild (onode)<br />
Set inode = xmldoc.createNode("element", "Address", "") </p>
<p>onode.appendChild (inode) </p>
<p>Set child = xmldoc.createNode("element", "Address1", "")<br />
child.Text = "Nepean Ont" </p>
<p>inode.appendChild (child) </p>
<p>Set child = xmldoc.createNode("element", "Address2", "")<br />
child.Text = "Canada"<br />
inode.appendChild (child) </p>
<p>End If </p>
<p>xmldoc.save (Server.Mappath("savedI2.xml")) </p>
<p>%&gt; </code></p>
<p>In the example above we create an XMLDOM Object. We then create a root node and its child node using the createNode function. Next, we append the nodes after assigning the text property to each of them. Finally, we save the in-memory XML tree to a file, savedI2.xml. </p>
<p>We can also build an XML file from the results of a database query. I&#8217;ve included two files with the support material for this article: pubtest.asp and saved.xsl. Pubtest.asp connects to the SQL Server 2000 pubs database, retrieving several records from the author&#8217;s table, formatting them as a new XML document and saving that document as saved.xml. </p>
<p>The saved.xsl file contains an XSL style sheet which is used by pubtest.asp to format saved.xml as HTML. You should download the support material before continuing. </p>
<p>Here&#8217;s an exert from pubtest.asp: </p>
<p><code>Do While Not rs.EOF<br />
Set onode = xmldoc.createNode("element", "Employee", "")<br />
xmldoc.documentElement.appendChild (onode)<br />
Set inode = xmldoc.createNode("element", "Name", "")<br />
inode.Text = rs.fields(0) &#038; " " &#038; rs.fields(1)<br />
onode.appendChild (inode) </p>
<p>'Grab another recordset based on the authored<br />
Sql = "select title_id,royaltyper from titleauthor " &#038; _<br />
"where au_id = '" &#038; rs.fields(2) &#038; "'" </p>
<p>Set rs2 = conn.Execute(Sql) </p>
<p>If Not (rs2.EOF = True And rs2.bof = True) Then<br />
Set inode = xmldoc.createNode("element", "Titles", "")<br />
onode.appendChild (inode)<br />
Set child = xmldoc.createNode("element", "TitleId", "")<br />
child.Text = rs2.fields(0)<br />
inode.appendChild (child)<br />
Set child = xmldoc.createNode("element", "royalty", "")<br />
child.Text = rs2.fields(1)<br />
inode.appendChild (child)<br />
rs2.Close<br />
Set rs2 = Nothing<br />
End If </p>
<p>rs.movenext<br />
Loop </code></p>
<p>One of the XML elements that results from the ASP code shown above looks like this:</p>
<p><code>&lt;Hi-Tech&gt;<br />
&lt;Employee&gt;<br />
&lt;Name&gt;Bennet Abraham&lt;/Name&gt;<br />
&lt;Titles&gt;<br />
&lt;TitleId&gt;BU1032&lt;/TitleId&gt;<br />
&lt;royalty&gt;60&lt;/royalty&gt;<br />
&lt;/Titles&gt;<br />
&lt;/Employee&gt; </code></p>
<p>Here&#8217;s an extract from the XSL style sheet file, saved.xsl: </p>
<p><code>&lt;xsl:for-each select="Hi-Tech/Employee"&gt;<br />
&lt;TR&gt;<br />
&lt;TD WIDTH="40%" BGCOLOR="lightyellow"&gt;<br />
&lt;FONT FACE="Verdana" SIZE="2" COLOR="black"&gt;<br />
&lt;xsl:value-of select="Name" /&gt;<br />
&lt;/FONT&gt;<br />
&lt;/TD&gt;<br />
&lt;TD WIDTH="30%" BGCOLOR="lightyellow"&gt;<br />
&lt;FONT FACE="Verdana" SIZE="2" COLOR="black"&gt;<br />
&lt;xsl:value-of select="Titles/TitleId" /&gt;<br />
&lt;/FONT&gt;<br />
&lt;/TD&gt;<br />
&lt;TD WIDTH="30%" BGCOLOR="lightyellow"&gt;<br />
&lt;FONT FACE="Verdana" SIZE="2" COLOR="black"&gt;<br />
&lt;xsl:value-of select="Titles/royalty" /&gt;<br />
&lt;/FONT&gt;<br />
&lt;/TD&gt;<br />
&lt;/TR&gt;<br />
&lt;/xsl:for-each&gt; </code></p>
<p>When I ran pubtest.asp in my browser, here&#8217;s what it looked like: </p>
<p><center><img src="http://images.ientrymail.com/xmlpronews/111904figure1.gif"></center></p>
<p>Let&#8217;s now run through the entire process of retrieving data from the pubs database, saving it to an XML file, and loading and transforming this document as XSL with the MSXML parser.</p>
<p><b>Our XML example explained</b></p>
<p>Firstly, we connect to SQL Server 2000 using a system DSN. The DSN is called &#8220;pubs&#8221;, and you should create the DSN using control panel. It should connect to your SQL server, more specifically to its pubs database. We instantiate an ADO connection object, passing in the DSN to its open method: </p>
<p><code>'Open database connection<br />
Set conn = Server.CreateObject("ADODB.Connection")<br />
dsn = "DSN=pubs;UID=sa;PWD="<br />
conn.Open dsn </code></p>
<p>Once we&#8217;re connect to our database, we create a new XML document and assign it a root element called &#8220;Hi-Tech&#8221;. We then proceed to retrieve a recordset from the authors table of our pubs database: </p>
<p><code>If (xmldoc.childNodes.length = 0) Then<br />
' Build the XML document<br />
Set root = xmldoc.createNode("element", "Hi-Tech", "")<br />
xmldoc.appendChild (root)<br />
' Queries the database for customer data<br />
Sql = "select au_lname,au_fname,au_id from authors"<br />
Set rs = conn.Execute(Sql)<br />
rs.MoveFirst </code></p>
<p>We then loop through each record in the recordset, appending its title, titleID and royalty fields to the XML document that we created earlier. We use the createNode and appendChild methods to do so: </p>
<p><code>Set inode = xmldoc.createNode("element", "Titles", "")<br />
onode.appendChild (inode)<br />
Set child = xmldoc.createNode("element", "TitleId", "")<br />
child.Text = rs2.fields(0)<br />
inode.appendChild (child)<br />
Set child = xmldoc.createNode("element", "royalty", "")<br />
child.Text = rs2.fields(1)<br />
inode.appendChild (child) </code></p>
<p>Once we&#8217;ve retrieved each of the records from the recordset and appended them to our XML document, we save the XML document to our local machine using MSXML&#8217;s save method: </p>
<p><code>xmldoc.save server.mappath("saved.xml") </code></p>
<p>We&#8217;re now at the point where we have an XML file called saved.xml, as well as the style sheet that&#8217;s included in the support material for this article, called saved.xml. We instantiate a new XMLDOM object for each of these files, calling the transformNode method of the XML DOM object with a reference to the XML DOM object that contains the XSL file: </p>
<p><code>sourceFile = Server.MapPath("saved.xml")<br />
styleFile = Server.MapPath("saved.xsl")<br />
set source = Server.CreateObject("Microsoft.XMLDOM")<br />
source.async = false<br />
source.load(sourceFile)<br />
set style = Server.CreateObject("Microsoft.XMLDOM")<br />
style.async = false<br />
style.load(styleFile) </code></p>
<p>Lastly, we use Response.Write to output the transformed XML to the browser: </p>
<p><code>Response.Write source.transformNode(style)</code></p>
<p><b>Conclusion</b></p>
<p>Well, I hope this article has answered some of your questions on XML. Hopefully you&#8217;ve learned a thing or two about the advantages and disadvantages of using XML, when it can be used, and most importantly, how it can be used.</p>
<p>Nakul Goyal : A Master of Sciences in Information Technology from Panjab University, Chandigarh and a Bachelor of Computer Applications from Punjab Technical University, Jalandhar, India. He is passionate towards the Cyber World &#038; he likes to write about Technology. He&#8217;s a Microsoft Certified Professional, a Brainbench Certified &#8216;MVP&#8217; (Most Valuable Professional), Brainbench Certified Internet professional and a CIW (Certified Internet Webmaster) Associate. Professionally, Nakul is the co-founder of a Web Designing, Search Engine Optimization Company.</p>
<p>Website: http://www.nakulgoyal.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/xml-strengths-and-weaknesses-with-dom-asp-and-xsl-2004-11/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paging mechanism using XML+XSLT</title>
		<link>http://www.webpronews.com/paging-mechanism-using-xmlxslt-2004-08</link>
		<comments>http://www.webpronews.com/paging-mechanism-using-xmlxslt-2004-08#comments</comments>
		<pubDate>Tue, 03 Aug 2004 17:17:46 +0000</pubDate>
		<dc:creator>Stanimir Stanev</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=10973</guid>
		<description><![CDATA[XSLT works pretty good to transform XML documents, but the things are getting much better when we are able to pass arguments to the XSL. This article will show how arguments can be passed without server side logic involved.
]]></description>
			<content:encoded><![CDATA[<p>XSLT works pretty good to transform XML documents, but the things are getting much better when we are able to pass arguments to the XSL. This article will show how arguments can be passed without server side logic involved.</p>
<p>Almost every web project has a part where a large list of items needs to be shown on the user&#8217;s browser. Imagine that we have a list with thousands of items, we do not want to show them on one web page, but rather have a navigation bar to scroll between different pages of the list. The goal is clear and there are plenty of ideas how to accomplish that generating dynamic pages with JSP, PHP, and ASP for example. But how about a pure XML+XSLT solution, where there is no logic on the server to generate the dynamic content, but all happens on the user&#8217;s browser. </p>
<p><b>1. The XML</b></p>
<p>The XML (mylist.xml) is pretty simple. It has a list of items. Every item has element1 and element2 children. The idea is that the items to be many, but for simplicity the example has only 10 and the goal is to show them by 3 on one page having &#8220;Prev&#8221; and &#8220;Next&#8221; links to navigate. Click on <a href="http://www.stanev.com/articles/paging_using_xsl/driver.html">driver.html</a> (IE only) for a working example. </p>
<p><code>&lt;?xml version="1.0"?&gt;<br />
&lt;list&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 1 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 1 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 2 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 2 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 3 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 3 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 4 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 4 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 5 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 5 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 6 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 6 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 7 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 7 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 8 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 8 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 9 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 9 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&#038;nbsp  &lt;item&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element1&gt;item 10 - element 1&lt;/element1&gt;<br />
&#038;nbsp&#038;nbsp    &lt;element2&gt;item 10 - element 2&lt;/element2&gt;<br />
&#038;nbsp  &lt;/item&gt;<br />
&lt;/list&gt;</code></p>
<p><a name="controller"></a><b>2. The controller XML</b></p>
<p>The main question is how to pass arguments to XSL that will be used for the transforming of our original mylist.xml. The answer is that we create a very simple XML. It has elements and attributes that can be treated as arguments when parsed from the XSL. We are going to have 3 arguments: </p>
<li>the index of the first item that is going to be shown </li>
<li>the number of items per page </li>
<li>the name of the original XML document containing all items </li>
<p>We call this a controller XML:</p>
<p><code>&lt;?xml version="1.0"?&gt;<br />
&lt;xml-controller&gt;<br />
&#038;nbsp  &lt;xml-doc-name start="1" limit="3"&gt;mylist.xml&lt;/xml-doc-name&gt;<br />
&lt;/xml-controller&gt;</code></p>
<p><b>3. The XSL</b></p>
<p>First, the XSL matches the /xml-controller/xml-doc-name element (line 4) from the controller XML to grab all arguments (lines 5-7). </p>
<p>Second, it loads the original XML document (lines 9-10) using the document XSL function. The interesting part (line 10) is that it uses XPath expression to select only elements that have position greater or equal than the start variable and less or equal than the end variable. This part is essential of implementing the paging mechanism. </p>
<p>The rest (lines 12-38) generates the HTML and shows the elements in a table. Lines 18-20 generate the &#8220;Prev&#8221; link if necessary and line 23 generates the &#8220;Next&#8221; link. Lines 30-35 generate all elements that have matched our criteria at line 10. </p>
<p><img src="http://images.ientrymail.com/xmlpronews/080204figure1.gif"></p>
<p><b>4. The JavaScript</b></p>
<p>Remember that our goal was everything to happen on the user&#8217;s browser (no server side logic), so finally, we need an HTML page that has JavaScript, which drives the XSLT transformation. </p>
<p>We assume that the XML and XSL documents are in the same folder where this page is, so the JavaScript gets the portion of the URL up to the page name (lines 10-12). This part will be used later when we load the XML document with the document XSL function, otherwise we will get an &#8220;Access Denied&#8221;. </p>
<p>We parse the URL this page is loaded from and get all arguments (lines 15-17), which we will use to build the controller XML that is being processed by the XSL. </p>
<p>We build the controller XML (lines 20-24), then load it (lines 27-29), load the XSL (lines 32-34), and proceed with the transformation (line 37). </p>
<p>Notice that this JavaScript uses the Microsoft.XMLDOM object, which makes it work only under Internet Explorer. However with a small change you can make it work under Netscape as well. </p>
<p><img src="http://images.ientrymail.com/xmlpronews/080204figure2.gif"></p>
<p><b>5. Conclusion</b></p>
<p>This example does not use server side logic, which is interesting, but makes the whole XML to be loaded from the browser first and then only a part of it shown. Although this is not a good practice, it gives the idea of passing arguments to an XSL via a very simple XML that we called a controller. </p>
<p>All source codes are available for download: <a href="http://www.xmlpronews.com/mylist1.xml">mylist.xml</a>, <a href="http://www.xmlpronews.com/mylist.xsl">mylist.xsl</a>, and <a href="http://www.stanev.com/articles/paging_using_xsl/driver.html">driver.html</a> (IE only)</p>
<p>My name is Stanimir Stanev. I am working as Senior Java Developer for<br />
CEO Consulting in Austin Texas. The last 4 years I am working on several<br />
Java projects at IBM that are part of self-monitoring systems.</p>
<p><a href="http://www.stanev.com">www.stanev.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/paging-mechanism-using-xmlxslt-2004-08/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating an Online RSS News Aggregator with ASP.NET Part 4</title>
		<link>http://www.webpronews.com/wpn-27-20040610CreatinganOnlineRSSNewsAggregatorwithASPNETPart4.html-2004-06</link>
		<comments>http://www.webpronews.com/wpn-27-20040610CreatinganOnlineRSSNewsAggregatorwithASPNETPart4.html-2004-06#comments</comments>
		<pubDate>Thu, 10 Jun 2004 19:14:22 +0000</pubDate>
		<dc:creator>Scott Mitchell</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Online]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=10386</guid>
		<description><![CDATA[Displaying the News Items for a Particular Syndication Feed

The next task that faces us is creating the DisplayNewsItems.aspx Web page. This page should display the titles of the news items in the selected syndication feed as hyperlinks such that when the hyperlink is clicked the description of the news item is shown in the bottom right frame. This task presents us with two primary challenges:
]]></description>
			<content:encoded><![CDATA[<p>Displaying the News Items for a Particular Syndication Feed</p>
<p>The next task that faces us is creating the DisplayNewsItems.aspx Web page. This page should display the titles of the news items in the selected syndication feed as hyperlinks such that when the hyperlink is clicked the description of the news item is shown in the bottom right frame. This task presents us with two primary challenges:</p>
<li>Accessing the RSS syndication feed from the feed&#8217;s specified URL, and </li>
<li>Transforming the XML received into the appropriate HTML. </li>
<p>Fortunately with the .NET Framework, neither of these two challenges is particularly daunting. For the first task, realize that remote XML data can be loaded into an XmlDocument object with just two lines of code. For the second task, displaying XML in an ASP.NET Web page is a cinch with the ASP.NET XML Web control.</p>
<p>The XML Web control is designed to display raw or transformed XML data on a Web page. The first step in using the XML Web control is specifying the XML data source. This can be accomplished in a bevy of ways through three different properties. Using the Document property, you can assign an XmlDocument instance as the XML data source for the XML Web control. If the XML data exists in a file on the Web server&#8217;s file system, you can use the DocumentSource property, providing either a relative or absolute path to the XML file. Finally, if you have the XML data in a string, you can set this string to the XML Web control&#8217;s DocumentContent property. Any of these three approaches can be used to associate XML data with the XML Web control.</p>
<p>Typically we&#8217;ll want to transform the XML data in some manner before displaying it on the Web page. The XML Web control allows us to specify an XSLT stylesheet that will apply the transformation. Similar to the XML data, the XSLT stylesheet can be specified in one of two ways through one of two properties: the Transform property can be assigned an XslTransform instance or the TransformSource property can be set to a relative or absolute file path to the XSLT stylesheet on the local Web server. In a moment, we&#8217;ll see an example of the XML Web control in action.</p>
<p>Let&#8217;s get to creating the DisplayNewsItems.aspx Web page. Before we add an XML Web control and start creating the code-behind class, we need to add a small bit of client-side JavaScript to the HTML portion. Specifically, add the following &lt;script&gt; block in the &lt;head&gt; tag of the HTML portion:</p>
<p><code>&lt;script language="javascript"&gt;<br />
&#038;nbsp  // display a blank page in the bottom frame when the news items loads<br />
 &#038;nbsp parent.rbottom.location.href = "about:blank";<br />
&lt;/script&gt;</code></p>
<p>This client-side JavaScript displays a blank page in the bottom right frame whenever DisplayNewsItems.aspx is loaded. To understand why we want to do this consider the following situation that can unfold if we omit this &lt;script&gt;block: </p>
<p><b>1. </b>The user clicks on a syndication feed from the left frame, thereby loading the feed&#8217;s news items in the top right frame. </p>
<p><b>2. </b>The user then clicks one of the news items from the top right frame, thereby loading the news item&#8217;s details in the bottom right frame. </p>
<p><b>3.</b> Now the user clicks on a different syndication feed from the left frame, thereby loading the new feed&#8217;s news items in the top right frame.<br />
At this point, the details from the previous syndication feed&#8217;s news item are still in the bottom right frame! The above client-side script code alleviates this glitch by &#8220;whipping out&#8221; the contents of the bottom right frame every time a syndication feed from the left frame is clicked.</p>
<p>Now that we have taken care of that client-side scripting issue, let&#8217;s turn our attention to adding the needed XML Web controls. Once you have added the XML Web control, set its ID property to xsltNewsItems and its TransformSource property to NewsItems.xslt (the name of the XSLT stylesheet we&#8217;ll create next). Now, in the Page_Load event handler we need to retrieve the remote RSS syndication file in an XmlDocument instance, and then set the XML Web control&#8217;s Document property to this XmlDocument instance.</p>
<p><code>private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
&#038;nbsp &#038;nbsp  // See if the news items for this feed are in the Data Cache<br />
&#038;nbsp&#038;nbsp   int feedID = Int32.Parse(Request.QueryString["FeedID"]);</p>
<p>&#038;nbsp&#038;nbsp   // Connect to the Database to find out the URL to the RSS<br />
&#038;nbsp&#038;nbsp   SqlConnection myConnection = new SqlConnection(connection string);</p>
<p>&#038;nbsp&#038;nbsp   // Retrieve the SQL URL for the Remote RSS syndication file<br />
&#038;nbsp&#038;nbsp   string SQL_QUERY = "SELECT URL, UpdateInterval FROM Feeds " +<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                      "WHERE FeedID = @FeedID";<br />
&#038;nbsp&#038;nbsp   SqlCommand myCommand = new SqlCommand(SQL_QUERY, myConnection);</p>
<p>&#038;nbsp&#038;nbsp   SqlParameter feedParam = new SqlParameter("@FeedID",<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                                          SqlDbType.Int, 4);<br />
&#038;nbsp&#038;nbsp   feedParam.Value = feedID;<br />
&#038;nbsp&#038;nbsp   myCommand.Parameters.Add(feedParam);</p>
<p>&#038;nbsp&#038;nbsp   myConnection.Open();<br />
&#038;nbsp&#038;nbsp   string feedURL = myCommand.ExecuteScalar().ToString()<br />
&#038;nbsp&#038;nbsp   myConnection.Close();</p>
<p>&#038;nbsp&#038;nbsp   // Now that we have the feed URL, load it in into an XML document<br />
&#038;nbsp&#038;nbsp   <b>XmlDocument feedXML = new XmlDocument();<br />
&#038;nbsp&#038;nbsp   feedXML.Load(feedURL);</p>
<p>&#038;nbsp&#038;nbsp   xmlNewsItems.Document = feedXML;</b></code><br />
}<br />
The most germane lines of code in the Page_Load event handler are the last three. These three lines of code create the new XmlDocument object, load in the remote RSS feed, and assign the XmlDocument object to the XML Web control&#8217;s Document property. Isn&#8217;t it impressive how simple it is to access remote XML data and display it in an ASP.NET Web page?</p>
<p>All that we have left to do now is create the XSLT stylesheet, NewsItems.aspx. This first draft of this stylesheet can be seen below:</p>
<p><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br />
&lt;xsl:stylesheet version="1.0"<br />
&#038;nbsp &#038;nbsp&#038;nbsp&#038;nbsp           xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
 &#038;nbsp  &lt;xsl:output method="html" omit-xml-declaration="yes" /&gt;</p>
<p>&#038;nbsp   &lt;xsl:template match="/rss/channel"&gt;<br />
 &#038;nbsp&#038;nbsp     &lt;b&gt;&lt;xsl:value-of select="title"<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                   disable-output-escaping="yes" /&gt;&lt;/b&gt;<br />
 &#038;nbsp&#038;nbsp     &lt;xsl:for-each select="item"&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp        &lt;li&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp           &lt;a&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp              &lt;xsl:attribute name="href"&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 DisplayItem.aspx?ID=&lt;xsl:number value="position()" /&gt;<br />
   &lt;/xsl:attribute&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp              &lt;xsl:attribute name="target"&gt;rbottom&lt;/xsl:attribute&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp              &lt;xsl:value-of select="title"<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                      disable-output-escaping="yes"  /&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp &#038;nbsp          &lt;/a&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp          (&lt;xsl:value-of select="pubDate" /&gt;)<br />
  &#038;nbsp&#038;nbsp&#038;nbsp       &lt;/li&gt;<br />
 &#038;nbsp&#038;nbsp     &lt;/xsl:for-each&gt;<br />
  &#038;nbsp &lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p>
<p>This XSLT stylesheet has a single template that matches on the /rss/channel XPath expression, outputting the value of the &lt;title&gt; element in a bold font. Next, it iterates through each of the &lt;item&gt; elements and, for each, displays a hyperlink to DisplayItem.aspx, passing the <item> element&#8217;s position through the querystring. Note that this hyperlink also has its target attribute set to rbottom, the name of the bottom right frame. Finally, it displays the value of the &lt;pubDate&gt; element after each news item title.</p>
<p>There are a couple of items in the XSLT stylesheet that not everyone may be familiar with. The first of these is the disable-output-escaping=&#8221;yes&#8221; attribute in the <xsl:value-of> elements. Essentially, this attribute setting informs the XSLT engine that it should not escape those illegal XML characters-&#038;, < , >, &#8221; and &#8216;. To understand what this accomplishes, realize that if this attribute were not set (or was set to the default value, &#8220;no&#8221;), then if the title contained an escaped &#038; as &amp;, the resulting HTML would have &amp; in it as well, as opposed to just &#038;. If you think about this for a bit, you can see that this can cause a multitude of problems. For example, if the title for a syndication file is: &#8220;Matt&#8217;s &lt;i&gt;Cool&lt;/i&gt; Blog&#8221;, then if output escaping is not disabled, then the output would remain &#8220;Matt&#8217;s &lt;i&gt;Cool&lt;/i&gt; Blog&#8221; and would be shown in the Web page as, &#8220;Matt&#8217;s &lt;i&gt;Cool&lt;/i&gt; Blog&#8221;. With disable-output-escaping=&#8221;yes&#8221;, however, the output is not escaped and is read as &#8220;Matt&#8217;s &lt;i&gt;Cool&lt;/i&gt; Blog&#8221;, thereby displaying in the Web page as the desired &#8220;Matt&#8217;s Cool Blog&#8221;.</p>
<p>Another thing to note is the &lt;a&gt; element. Realize that this funky syntax ends up generating the following output:</p>
<p><code>&lt;a href="DisplayItem.aspx?ID=position"&gt;news item title&lt;/a&gt;</code></p>
<p>The reason we have to use this syntax is because in order to add an attribute to an element in an XSLT stylesheet you need to create the element and then inside of the element&#8217;s tags, use the &lt;xsl:attribute&gt; syntax. There are some examples of this syntax available online at W3Schools, The &lt;xsl:attribute&gt; Element page.</p>
<p>Finally, note that the ID querystring value in the hyperlink is assigned the value from the &lt;xsl:number&gt; element, with a value of the position() function. The <xsl:number> element simply emits a number. The position() function is an XPath function that returns the ordinal position of the current node in the XML document. This means the first news item will have a position() value of 1; the second, a position() value of 2; and so on. We need to record this value and pass it along via the querystring so that when the DisplayItem.aspx Web page is called, it knows what item from the RSS syndication feed we are interested in viewing.</p>
<p>The astute reader may have realized that our XSLT stylesheet is not complete due to the fact that the FeedID parameter is not passed through the querystring to the DisplayItem.aspx Web page. To see why this is a problem, recall that we are sending in the ID querystring parameter the ordinal position of the <item> element the user is interested in viewing the details for. That is, if the user clicks on the fourth news item, the page DisplayItem.aspx?ID=4 will be loaded in the bottom right frame. The problem is that DisplayItem.aspx cannot determine what feed the user is interested in viewing. There are a couple of ways to figure this out, such as having the bottom right frame use client-side JavaScript to read the URL of the top right frame, thereby ascertaining the value of FeedID. A simpler way, in my opinion, is to merely pass along the FeedID value through the querystring along with the ID parameter.</p>
<p>One difficulty that arises from this is that FeedID is not present in the RSS XML data, which is what the XSLT stylesheet is working with. The DisplayNewsItems.aspx Web page knows the FeedID, though, and needs to somehow let the XSLT stylesheet know this value. This can be accomplished through the use of XSLT parameters.</p>
<p>Using XSLT parameters is fairly straightforward. In the XSLT stylesheet, you need to add inside the &lt;xsl:template&gt; element an &lt;xsl:param&gt; element, which provides the name for the parameter. Let&#8217;s call this parameter FeedID:</p>
<p><code>&lt;xsl:stylesheet version="1.0"<br />
&#038;nbsp&#038;nbsp       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;</p>
<p>   &lt;xsl:template match="/rss/channel"&gt;<br />
      &lt;xsl:param name="FeedID" /&gt;</p>
<p>                ...<br />
   &lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p>
<p>Now, the parameter can be used in an &lt;xsl:value-of&gt; element using the following syntax:</p>
<p><code>&lt;xsl:value-of select="$parameterName" /&gt;</code></p>
<p>Therefore, we can add the FeedID querystring parameter to the hyperlink by adding the following to our existing XSLT stylesheet:</p>
<p><code>&lt;a&gt;<br />
&#038;nbsp  &lt;xsl:attribute name="href"&gt;DisplayItem.aspx?ID=&lt;xsl:number<br />
 &#038;nbsp&#038;nbsp   value="position()" /&gt; &amp;FeedID=&lt;xsl:value-of select="$FeedID"<br />
&#038;nbsp&#038;nbsp&#038;nbsp      /&gt;&lt;/xsl:attribute&gt;</code></p>
<p>Note that we have an ampersand (escaped to &amp;) after the ID querystring parameter, and then have the querystring parameter FeedID with the value from the FeedID parameter. That&#8217;s all we have to add to our XSLT stylesheet.</p>
<p>What remains is to set the parameter&#8217;s value programmatically in the Page_Load event handler of the DisplayNewsItems.aspx Web page. This is accomplished using the XsltArgumentList class. This class contains an AddParameter() method. Once we have created an instance of this class and added the parameter, we simply set the class instance to the XML Web control&#8217;s TransformArgumentList parameter. The following code shows the updated Page_Load event handler for DisplayNewsItems.aspx:</p>
<p><code>private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
        ...</p>
<p>&#038;nbsp   // Now that we have the feed URL, load it in into an XML document<br />
 &#038;nbsp  XmlDocument feedXML = new XmlDocument();<br />
&#038;nbsp   feedXML.Load(feedURL);</p>
<p>&#038;nbsp   xmlNewsItems.Document = feedXML;</p>
<p>&#038;nbsp   // Add the FeedID parameter to the XSLT stylesheet<br />
 &#038;nbsp  <b>XsltArgumentList xsltArgList = new XsltArgumentList();<br />
 &#038;nbsp  xsltArgList.AddParam("FeedID", "", feedID);<br />
&#038;nbsp   xmlNewsItems.TransformArgumentList = xsltArgList;</b>}</code></p>
<p>*This article originally appeared on the <a href="http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-createrssw-aspnet.asp">ASP.NET Dev Center at MSDN</a></p>
<p><a href="http://www.4GuysFromRolla.com/ScottMitchell.shtml">Scott Mitchell</a>, author of five ASP/ASP.NET books and founder of <a href="http://www.4GuysFromRolla.com">4GuysFromRolla.com</a>, has been working with Microsoft Web technologies for the past five years. An active member in the ASP and ASP.NET community, Scott is passionate about ASP and ASP.NET and enjoys helping others learn more about these exciting technologies. For more on the DataGrid, DataList, and Repeater controls, check out Scott&#8217;s book ASP.NET Data Web Controls Kick Start (ISBN: 0672325012). Read his blog at : http://scottonwriting.net</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/wpn-27-20040610CreatinganOnlineRSSNewsAggregatorwithASPNETPart4.html-2004-06/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying the Details for a Particular News Item</title>
		<link>http://www.webpronews.com/displaying-the-details-for-a-particular-news-item-2004-06</link>
		<comments>http://www.webpronews.com/displaying-the-details-for-a-particular-news-item-2004-06#comments</comments>
		<pubDate>Thu, 10 Jun 2004 13:54:10 +0000</pubDate>
		<dc:creator>Scott Mitchell</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[syndication]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=10378</guid>
		<description><![CDATA[This is Part 5 of a 5 part article "Creating An Online RSS News Aggregator With ASP.NET".
]]></description>
			<content:encoded><![CDATA[<p>This is Part 5 of a 5 part article &#8220;Creating An Online RSS News Aggregator With ASP.NET&#8221;.</p>
<p>All that remains left to do is to display the detailed information for the particular news item the user selected. This detailed information will be displayed in the bottom right frame, and will show the title of the news item entry, its description, and a link to the news item. As with the DisplayNewsItem.aspx Web page, DisplayItem.aspx starts by retrieving the remote RSS syndication feed based on the passed-in FeedID querystring parameter. It then uses an XML Web control to display the detailed information. In fact, the Page_Load event handler for the DisplayItem.aspx Web page is identical to the DisplayNewsItem.aspx Web page&#8217;s Page_Load event handler save for two minor differences:</p>
<li>DisplayItem.aspx needs to read in the value of the ID querystring parameter, and </li>
<li>DisplayItem.aspx uses an XSLT parameter, but one different from DisplayNewsItem.aspx. </li>
<p>As with DisplayNewsItem.aspx, DisplayItem.aspx needs to pass in a parameter into the XSLT stylesheet. Whereas DisplayNewsItem.aspx passed in the querystring parameter for FeedID, DisplayItem.aspx needs to pass in the ID querystring parameter, which indicates what news item the XSLT stylesheet should display. These minor changes are shown in the Page_Load event handler below in a bold font; code identical to the Page_Load event handler from DisplayNewsItems.aspx has been omitted:</p>
<p><code>private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
&#038;nbsp   // See if the news items for this feed are in the Data Cache<br />
&#038;nbsp   int feedID = Int32.Parse(Request.QueryString["FeedID"]);<br />
&#038;nbsp   <b>int ID = Int32.Parse(Request.QueryString["ID"]);</b></p>
<p>   ...</p>
<p> &#038;nbsp  // Now that we have the feed URL, load it in into an XML document<br />
 &#038;nbsp  XmlDocument feedXML = new XmlDocument();<br />
 &#038;nbsp  feedXML.Load(feedURL);</p>
<p> &#038;nbsp  xmlNewsItems.Document = feedXML;</p>
<p>&#038;nbsp   this.xmlItem.Document = feedXML;</p>
<p>&#038;nbsp   // Add the ID parameter to the XSLT stylesheet<br />
&#038;nbsp  <b> XsltArgumentList xsltArgList = new XsltArgumentList();<br />
&#038;nbsp   xsltArgList.AddParam("ID", "", ID);<br />
 &#038;nbsp  xmlItem.TransformArgumentList = xsltArgList;</b>}</code></p>
<p>The XSLT stylesheet to transform the XML data can be seen below:</p>
<p><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br />
&lt;xsl:stylesheet version="1.0"<br />
&#038;nbsp&#038;nbsp&#038;nbsp          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
&#038;nbsp   &lt;xsl:output method="html" omit-xml-declaration="yes" /&gt;<br />
&#038;nbsp   <b>&lt;xsl:param name="ID" /&gt;</b></p>
<p>&#038;nbsp   &lt;xsl:template match="/rss/channel"&gt;<br />
&#038;nbsp&#038;nbsp      &lt;b&gt;&lt;xsl:value-of select="<b>item[$ID]/title"</b><br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                           disable-output-escaping="yes" /&gt;&lt;/b&gt;<br />
&#038;nbsp&#038;nbsp      &lt;p&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp         &lt;xsl:value-of select="<b>item[$ID]/description</b>"<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                           disable-output-escaping="yes" /&gt;<br />
&#038;nbsp&#038;nbsp      &lt;/p&gt;<br />
&#038;nbsp&#038;nbsp      &lt;a&gt;<br />
&#038;nbsp&#038;nbsp         &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of<br />
&#038;nbsp&#038;nbsp           select="<b>item[$ID]/link</b>" /&gt;&lt;/xsl:attribute&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp         &lt;xsl:attribute name="target"&gt;_blank&lt;/xsl:attribute&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp         Read More...<br />
&#038;nbsp&#038;nbsp      &lt;/a&gt;<br />
&#038;nbsp   &lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p>
<p>Note that an &lt;xsl:param&gt; element is used to declare the ID XSLT parameter. Then, in the various &lt;xsl:value-of&gt; elements, the ID parameter is used to grab just the specific &lt;item&gt; element from the list of item elements. Realize that in XPath the syntax elementName[i] accesses just the Ith element with the appropriate element name. For example, item[1] would retrieve just the first &lt;item&gt; element, while item[2] would retrieve just the second. Therefore, item[$ID] retrieves just the &lt;item&gt; element as specified by the ID XSLT parameter.</p>
<p>Finally, note that the Read More hyperlink, outputted near the end of the XSLT stylesheet, has its target attribute set to blank, thereby causing a new window to be opened when a user clicks on the Read More link.</p>
<p><a name="Future"></a><br />
<h4>Future Enhancements and Current Shortcomings</h4>
<p>One glaring shortcoming with the code we examined in this article is that each time the user clicks on a syndication feed from the left frame, or clicks on a news item title from the top right frame, the remote RSS syndication feed is loaded and parsed. Clearly this is inefficient since once you click on a syndication feed all of the items are loaded; it is wasteful to reload the entire remote syndication feed each time the user clicks on one of the feed&#8217;s news item titles. Not only is this approach inefficient, but impolite to the person or company providing the syndication service, as these incessant and needless requests are placing an unnecessary load on their Web server.</p>
<p>This shortcoming is overcome in the source code you can download with this article. Specifically, the .NET Data Cache is used to store the XmlDocument object for the various feeds. The cache duration is set to the value of the feed&#8217;s UpdateInterval field in the Feeds table. (Of course, the feed&#8217;s XmlDocument object could be evicted from the cache at an earlier point in time for a variety of reasons.)</p>
<p>Another shortcoming of the system is that there is no state between the top right and bottom right frames. To see where this can lead to trouble, consider the following actions: </p>
<p><b>1.</b> A user clicks on a syndication feed link from the left frame, loading the feed&#8217;s news items in the top right frame. Assume that this syndication has an UpdateInterval value of 30, meaning that is expires in 30 minutes. </p>
<p><b>2.</b> In loading the news items in the top right frame, the feed is cached in the data cache. </p>
<p><b>3. </b>The user leaves for lunch. </p>
<p><b>4.</b> The Web site providing the syndication service adds a new news item. </p>
<p><b>5.</b> Our user returns from an hour lunch, meaning the XmlDocument for this feed in the data cache has expired. </p>
<p><b>6.</b> The user clicks on the first news item from the top right frame. This loads DisplayItem.aspx in the bottom frame, passing in an ID parameter value of 1. </p>
<p><b>7.</b> DisplayItem.aspx cannot find the XmlDocument in the cache, so it request the syndication feed from the remote source. In response it gets the new syndication feed (remember, a new news item was added back in step 4) and displays the first item (since the ID parameter equals 1). </p>
<p><b>8.</b> The user is displayed the new news item, which is a bit perplexing to the new news item is not displayed in the top right frame and was not the one they thought they clicked on. </p>
<p>This problem arises because the ID parameter does not uniquely identify each news item; rather, it is only an offset of the news item from a list of news items at a particular point in time. A good way of fixing this would be to stop using the data cache to store each syndication feed, and start using a database, or some other means of persistent storage (such as XML files on the Web server&#8217;s local file system). By using a database, each news item can be given a unique identifier, which can then be passed down to the bottom right frame. This approach guarantees against the problem outlined above. Of course this adds some additional complexities, such as deciding when to clear old items out of the database.</p>
<p>The existing application also lacks any exception handling. This should definitely be added. In particular, exception handling needs to be added for retrieving and loading the remote RSS syndication file into the XmlDocument object. The file might not exist, or might be malformed.</p>
<p>There are a plethora of enhancements that one could easily add to this online news aggregator. One obvious one would be an administration page to allow the user to add, remove and edit their existing syndication feeds. Also, it would be nice to allow the user to group their syndication feeds by user-created categories. The user interface is a bit hard on the eyes, but this could be quickly fixed by either augmenting the HTML generated by the XSLT stylesheets or adding stylesheets to the various frames to allow for a more aesthetic appearance. Finally, it would be worthwhile to add some <meta> HTML tags to cause the top right frame to refresh periodically so that the user can see new news items for a particular syndication feed without having to manually refresh the Web page.</p>
<p><b>Note (August 4, 2003):</b> After publication of this article, a few people emailed me informing me of two potential issues with displaying the <description> of a particular RSS syndication item the way I show in the article:</p>
<p><b>1.</b> Disable-output-encoding, which is used in the <xsl:value-of>, is not uniformly implemented by all XSLT parsers.  The .NET XSLT parser supports disable-output-encoding, but just be aware of this in case you attempt to port this application to other platforms.</p>
<p><b>2.</b> The HTML content in the &lt;description&gt; element is blindly emitted.  This HTML might contain malicious code, such as &lt;script&gt; or &lt;embed&gt; blocks which should, ideally, be stripped out.  In order to strip out these potentially offensive HTML elements, you would likely need to use extension functions (See Extending XSLT with JScript, C#, and Visual Basic .NET). For more information on the need for stripping HTML content from an RSS feed, refer to this &#8216;Dive Into Mark&#8217; blog entry.</p>
<h4>Summary</h4>
<p>In this article we examined building not only a syndication engine, but an online news aggregator as well. In building both products we worked with displaying XML data in an ASP.NET Web page. With the syndication engine, we displayed database data in an XML format using a Repeater control. In the news aggregator, we used XML Web controls with XSLT stylesheets.</p>
<p>I invite you to download the online news aggregator and make enhancements to it as you see fit. If you have any questions with regards to the application or the concepts discussed in this article, don&#8217;t hesitate to shoot me an email; I can be reached at <a href="http://mailto:mitchell@4guysfromrolla.com">mitchell@4guysfromrolla.com.</a></p>
<p>Happy Programming!</p>
<h4>Recommended Links</h4>
<li><a href="http://aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=204">Displaying XML Data in an ASP.NET Web Page </a></li>
<li>ASP.NET XML Web Control Technical Documentation: reference for the <a href="http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/cpref/html/frlrfSystemWebUIWebControlsXmlClassTopic.asp">XML Class </a></li>
<li><a href="http://www.w3schools.com/xsl/">XSLT Tutorial </a></li>
<li><a href="http://www.w3schools.com/xpath/">XPath Tutorial</a> </li>
<li>The <a href="http://asp.net/Forums/ShowForum.aspx?ForumID=43">XML Forum</a> at the ASP.NET Forums </li>
<p><a href="http://aspnet.4guysfromrolla.com/articles/022802-1.aspx">Caching with ASP.NET </a></p>
<p>*This article originally appeared on the <a href="http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-createrssw-aspnet.asp">ASP.NET Dev Center at MSDN</a></p>
<p><a href="http://www.4GuysFromRolla.com/ScottMitchell.shtml">Scott Mitchell</a>, author of five ASP/ASP.NET books and founder of <a href="http://www.4GuysFromRolla.com">4GuysFromRolla.com</a>, has been working with Microsoft Web technologies for the past five years. An active member in the ASP and ASP.NET community, Scott is passionate about ASP and ASP.NET and enjoys helping others learn more about these exciting technologies. For more on the DataGrid, DataList, and Repeater controls, check out Scott&#8217;s book ASP.NET Data Web Controls Kick Start (ISBN: 0672325012). Read his blog at : http://scottonwriting.net</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/displaying-the-details-for-a-particular-news-item-2004-06/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploring Data Islands and Web Services</title>
		<link>http://www.webpronews.com/exploring-data-islands-and-web-services-2003-12</link>
		<comments>http://www.webpronews.com/exploring-data-islands-and-web-services-2003-12#comments</comments>
		<pubDate>Mon, 08 Dec 2003 16:55:42 +0000</pubDate>
		<dc:creator>Alan Hyneman</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Click]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=8259</guid>
		<description><![CDATA[Please note - Data Islands are exclusive to Internet Explorer!

This month we start a two part series on Data Islands.  Part 1 explores how we can use Data Islands to embed XML and XSLT into a browser, and manipulate that data using DHTML.  Part 2 will illustrate Data Islands and Data Binding, and how to update data from the browser with Web Services and XMLHTTP.
]]></description>
			<content:encoded><![CDATA[<p>Please note &#8211; Data Islands are exclusive to Internet Explorer!</p>
<p>This month we start a two part series on Data Islands.  Part 1 explores how we can use Data Islands to embed XML and XSLT into a browser, and manipulate that data using DHTML.  Part 2 will illustrate Data Islands and Data Binding, and how to update data from the browser with Web Services and XMLHTTP.</p>
<p>Before you begin you should have a general idea of XML and XSLT.  If you are new to these technologies there are a number of resources out there that cover them in detail.  You&#8217;ll want to take a look at XML, XPath, and XSLT.  So off we go &#8230;</p>
<p>First up, what is a data island?  A data island provides the means to embed XML into the browser.  The following snippets show two possible ways to create a data island.</p>
<p><code>&lt;xml id="demoXML"&gt;<br />
 &lt;Some XML Here.....<br />
&lt;/xml&gt;<br />
or<br />
&lt;xml id="demoXSL" src="your-source.xml|xsl"/&gt;</code></p>
<p>The most important attribute of the xml is the <b>id attribute</b>, this is how you will refer to the Data Island in the browser.  Once your page loads you can manipulate the XML with the same syntax as the MSXML Parser. </p>
<p>Our example uses two Data Islands, one for XML and one for XSLT.  We will use DHTML to manipulate the XML and then transform the results. </p>
<p>Now that you have the XML in the browser you need a way to manipulate it. Our example uses two functions; the first function manipulates the XML by altering a &#8220;selected&#8221; attribute.  In the example that follows a grid is created with &#8220;where to buy&#8221; links.  The onclick event of the link calls the SetSelected function which manipulates the XML in the Data Island.</p>
<pre>function SetSelected(id)
{
  //Build the XPath Query based on the id passed in
  var query = "/my-list/my-item[@id='" + id + "']";
   //clear previously selected items
  var lst= demoXML.selectNodes("/my-list/my-item")
  for(ctr=0;ctr!=lst.length;ctr++)
  {
    lst[ctr].setAttribute("selected",0);
  }
  //Set the selected attribute of the currently selected node
  var elm = demoXML.selectSingleNode(query);
  elm.setAttribute("selected",1);
  Render();
}</pre>
<p>The second function simply does a transformation on the XML Island using the XSL Island and places the results in a div.</p>
<pre>function Render()
{
  list.innerHTML= demoXML.transformNode(demoXSL);
}</pre>
<p>Here&#8217;s our smart little page (kept to the minimum) that shows the Islands and functions in action. </p>
<p>Note &#8211; if you receive errors on this page make sure your box is running the latest greatest updates.  See the MSDN site for help pertaining to particular errors. </p>
<p>The browser currently contains two data islands. One for XML and one for XSL.  Start with the render link.  The where to buy links will call the SetSelected function.  If you click on a where to buy link and then click the Show XML link, you will see the selected attribute is set according to the ID of the item selected.</p>
<p><a href="http://www.enterprisesolutionsnetwork.com/ESNNews/October2003/October_2003_3.aspx">To see the XML, XSL, or to render, click here.</a></p>
<p>That&#8217;s it folks!  At this point you should be able to create a Data Island and manipulate it in the browser.  Our example used the onclick event of an <a> tag to manipulate the XML (although we could have used any event).  If you&#8217;re the creative type I hope I got your wheels spinning.</p>
<p>Next time as we move into data binding and XMLHTTP you will see that Data Islands are a powerful tool for enriching the user experience in web based applications.  So until then good luck!</p>
<p><a href="http://www.ientry.com/page/newsletters/"><u>Click here</u> <font color="red">to sign up for FREE Tech. newsletters from iEntry!</font></a></p>
<p>Alan Hyneman has been working with and using computers in numerous applications for over 20 years. His experiences range from Graphic Design and Desktop Publishing, through developing enterprise level back end engines utilizing SQL, ASP, VB, XML, XSLT, and C++. He holds Microsoft&#8217;s MCSD certification, Microsoft&#8217;s highest certification for software developers. He is available on a consultant or contract basis and is always ready to meet the needs of clients. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/exploring-data-islands-and-web-services-2003-12/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP, XML and XSL for Wireless Content</title>
		<link>http://www.webpronews.com/php-xml-and-xsl-for-wireless-content-2003-11</link>
		<comments>http://www.webpronews.com/php-xml-and-xsl-for-wireless-content-2003-11#comments</comments>
		<pubDate>Mon, 24 Nov 2003 16:36:40 +0000</pubDate>
		<dc:creator>Jason Lam</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=8102</guid>
		<description><![CDATA[This article is another illustration of why using PHP with XSL to transform XML data to various presentation layers is beneficial.  With that being said this article will demonstrate how to present the same data to several different wireless technologies using PHP and XSL, instead of an article completely focused on PHP and XSL.
]]></description>
			<content:encoded><![CDATA[<p>This article is another illustration of why using PHP with XSL to transform XML data to various presentation layers is beneficial.  With that being said this article will demonstrate how to present the same data to several different wireless technologies using PHP and XSL, instead of an article completely focused on PHP and XSL.</p>
<p>There are plenty of articles on the web that already do this, but most them only focus on presenting data through HTML.  This is what this article is for to give more examples of XSL other then with HTML.  A recent article on &#8220;Using PHP and XSL to Transform XML into Web Content&#8221; by Benson Wong is available at Zend.com.  </p>
<p>As well an installation on how to do a &#8220;Step by Step Install of Apache PHP SSL and more&#8221;, also includes XSL module, is available at<br />
<a href="http://www3.telus.net/jasonlam604/linux002.html">http://www3.telus.net/jasonlam604/linux002.html</a>. As well you can refer to<br />
<a href="http://www.xslt.com">http://www.xslt.com</a> or<br />
<a href="http://www.w3schools.com/default.asp">http://www.w3schools.com/default.asp</a> for more information on XSL.</p>
<p><b>Brief Recap of XSL and XML</b></p>
<p>XSL (eXtensible Stylesheet Language) is used to transform XML into data/form for a particular device whether it be a screen, voice or paper so that it can understand what the XML data is. Reason being XML tags are not predefined so devices like browsers are unable to understand XML and that is what XSL is for.  At the same time it allows for different stylesheets to be applied to the same XML data for different devices as the following examples will show.</p>
<p>The Familiar HTML</p>
<p>Okay, let us start with the familiar HTML example first. As well present the PHP code used to transform the stylesheet and the XML data itself.</p>
<p>PHP Source Code:</p>
<pre> &lt;?php
include_once("./xslt.class.php");
$xslt = new Xslt("c://data//books_html.xsl", "c://data//books.xml");
header("Content-type: text/html");
print ($xslt->transform());
?&gt;</pre>
<p>PHP Helper Class Source Code:</p>
<pre> class Xslt {
  var $xsl_file;
  var $xml_file;
  var $fileName;
  function Xslt($xsl_file = '', $xml_file = '') {
    $this->xsl_string = "file://" . $xsl_file;
    $this->xml_string = "file://" . $xml_file;
  }
  function transform() {
    $this->result = '';
    $xsltHandle = xslt_create();
    //xslt_set_base($xsltHandle,'file://c://php//xslxml//');
    $this->result = xslt_process($xsltHandle,$this->xml_string,$this->xsl_string);
    //$this->result = xslt_process($xsltHandle,'file://d://' . $this->xml_string,$this->xsl_string);
    if (!$this->result)
      die("Transformation failed");
    xslt_free($xsltHandle);
    return $this->result;
  }
}
</pre>
<p><b>XML File</b></p>
<p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;books&gt;<br />
 &#038;nbsp&#038;nbsp &lt;book&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;title&gt;Professional PHP4 Programming &lt;/title&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;author&gt;Deepak Thomas &lt;/author&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;price&gt; 49.99 &lt;/price&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;special&gt; 34.99 &lt;/special&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;size&gt; Paperback 974 pages ; Dimensions (in inches): 2.08 x 9.00 x 7.26 &lt;/size&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp    &lt;publisher&gt; Wrox Press Inc; 1st edition (January 2002) &lt;/publisher&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp    &lt;isbn&gt; 1861006918 &lt;/isbn&gt;<br />
&#038;nbsp&#038;nbsp &lt; /book&gt;<br />
 &#038;nbsp&#038;nbsp &lt;book&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;title&gt; PHP Fast and Easy Web Development, 2nd Edition &lt;/title&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;author&gt; Julie C. Meloni &lt;/author&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp    &lt;price&gt; 29.99 &lt;/price&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;special&gt; 0.00 &lt;/special&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;size&gt; Paperback 504 pages ; Dimensions (in inches): 1.03 x 9.24 x 7.32 &lt;/size&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;publisher&gt; Premier Press; 2 edition (August 26, 2002)  &lt;/publisher&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;isbn&gt; 193184187X &lt;/isbn&gt;<br />
&#038;nbsp&#038;nbsp &lt;/book &gt;<br />
 &#038;nbsp&#038;nbsp &lt;book&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;title &gt;PHP MySQL Website Programming: Problem - Design - Solution &lt;/title&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;author &gt;Chris Lea &lt;/author&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp    &lt;price&gt; 34.99 &lt;/price&gt;<br />
  &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp  &lt;special &gt;24.99 &lt;/special&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;size&gt; Hard Cover 500 pages ; Dimensions (in inches): 1.15 x 9.08 x 7.22 &lt;/size&gt;<br />
 &#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp   &lt;publisher&gt; Wrox Press Inc; (March 2003) &lt;/publisher&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp    &lt;isbn&gt; 1861008279 &lt;/isbn&gt;<br />
 &#038;nbsp&#038;nbsp &lt;/book &gt;<br />
&lt;/books&gt;<br />
</code></p>
<p><b>XSL File</b></p>
<p><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" &gt;<br />
&lt;xsl:template match="/"&gt;<br />
 &#038;nbsp &#038;nbsp &lt;html&gt;<br />
 &#038;nbsp &#038;nbsp &lt;body&gt;<br />
 &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp   &lt;h2&gt;PHP Books &lt;/h2&gt;<br />
  &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp   &lt; table border="0" cellspacing="0" cellpadding="0"&gt;<br />
  &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp    &lt; xsl:for-each select="books/book"&gt;<br />
   &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp   &lt; tr&gt;<br />
     &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp   &lt; td&gt;<br />
    &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp      &lt; u&gt; &lt; b&gt; &lt; xsl:value-of select="title"/&gt; &lt; /b&gt; &lt; /u&gt; &lt; br/&gt;<br />
     &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp     &lt; b&gt; &lt; xsl:text&gt; Author: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="author"/&gt; &lt; br/&gt;<br />
    &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp      &lt; b&gt; &lt; xsl:text&gt; Price: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="price"/&gt;<br />
          &lt; xsl:if test="special &gt;  0"&gt;<br />
 &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp           &lt; b&gt; &lt; xsl:text&gt;  On Sale For: &lt; /xsl:text&gt; &lt; xsl:value-of select="special"/&gt; &lt; /b&gt;<br />
     &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp     &lt; /xsl:if&gt; &lt; br/&gt;<br />
  &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp        &lt; b&gt; &lt; xsl:text&gt; Paperback: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="size"/&gt; &lt; br/&gt;<br />
          &lt; b&gt; &lt; xsl:text&gt; Publisher: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="publisher"/&gt; &lt; br/&gt;<br />
          &lt; b&gt; &lt; xsl:text&gt; ISBN: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="isbn"/&gt; &lt; br/&gt;<br />
&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp          &lt; br/&gt;<br />
  &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp      &lt; /td&gt;<br />
   &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp   &lt; /tr&gt;<br />
  &#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp    &lt; /xsl:for-each&gt;<br />
&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp    &lt; /table&gt;<br />
&#038;nbsp &#038;nbsp&#038;nbsp &#038;nbsp  &lt; /body&gt;<br />
  &#038;nbsp &#038;nbsp&lt; /html&gt;<br />
&lt; /xsl:template&gt;<br />
&lt; /xsl:stylesheet&gt;<br />
</code></p>
<p><b>Output:</b><br />
<center><img src="http://images.ientrymail.com/wirelesspronews/0926figure1.gif"></center></p>
<p>The XML file is your key file where dynamic data is stored, changed or removed. It does not affect any the layout of the pages themselves.  This you should already know.  After looking at the above code and from your experience working with XSL to transform XML files to HTML output, you are probably saying to yourself this is not worth it.  </p>
<p>I agree with you one hundred percent, not only is it a lot of work; but also requires you add to your skill set XSL and XML.  In fact, if there is no requirement to output the data to anything but a regular browser it might be in your best interest to simply stick to PHP and HTML.  But if you are going to support other devices or media you should seriously consider using PHP and XSL.  </p>
<p>The following three XSL transformations will demonstrate this, the technologies used will be WML, cHTML and VXML, </p>
<p><b>WML</b></p>
<p>PHP Source Code:</p>
<pre> &lt;?php
include_once("./xslt.class.php");
$xslt = new Xslt("c://data//books_wml.xsl", "c://data//books.xml");
header("Content-type: text/vnd.wap.wml");
print ($xslt->transform());
?&gt; </pre>
<p><b>XSL File</b></p>
<p><code>&lt; ?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt; xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;<br />
&lt; xsl:template match="/"&gt;<br />
 &#038;nbsp   &lt; wml&gt;<br />
&#038;nbsp&#038;nbsp       &lt; template&gt;<br />
&#038;nbsp    &#038;nbsp&#038;nbsp     &lt; do type="accept" label="Back"&gt; &lt; prev/&gt; &lt; /do&gt;<br />
    &#038;nbsp &#038;nbsp   &lt; /template&gt;<br />
&#038;nbsp&#038;nbsp       &lt; xsl:element name="card"&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp         &lt; xsl:attribute name="id"&gt; books&lt; /xsl:attribute&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp         &lt; xsl:attribute name="books"&gt; PHP Books&lt; /xsl:attribute&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp          &lt; p&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp             &lt; small&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp               &lt; xsl:for-each select="books/book"&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; u&gt; &lt; b&gt; &lt; xsl:value-of select="title"/&gt; &lt; /b&gt; &lt; /u&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; b&gt; &lt; xsl:text&gt; Author: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="author"/&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; b&gt; &lt; xsl:text&gt; Price: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="price"/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; xsl:if test="special &gt;  0"&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                   &lt; b&gt; &lt; xsl:text&gt;  On Sale For: &lt; /xsl:text&gt; &lt; xsl:value-of select="special"/&gt; &lt; /b&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; /xsl:if&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; b&gt; &lt; xsl:text&gt; Paperback: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="size"/&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; b&gt; &lt; xsl:text&gt; Publisher: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="publisher"/&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; b&gt; &lt; xsl:text&gt; ISBN: &lt; /xsl:text&gt; &lt; /b&gt; &lt; xsl:value-of select="isbn"/&gt; &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp                 &lt; br/&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp               &lt; /xsl:for-each&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp&#038;nbsp             &lt; /small&gt;<br />
&#038;nbsp&#038;nbsp&#038;nbsp          &lt; /p&gt;<br />
&#038;nbsp&#038;nbsp       &lt; /xsl:element&gt;<br />
&#038;nbsp    &lt; /wml&gt;<br />
&lt; /xsl:template&gt; </code></p>
<p><b>Output:</b><br />
<center><img src="http://images.ientrymail.com/wirelesspronews/0926figure2.gif"></center></p>
<p><b>cHTML</b></p>
<p>PHP Source Code:</p>
<pre>  &lt;?php
include_once("./xslt.class.php");
$xslt = new Xslt("c://data//books_chtml.xsl", "c://data//books.xml");
header("Content-type: text/html");
print ($xslt->transform());
?&gt;  </pre>
<p><b>XSL File</b></p>
<p><code>&lt; ?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt; xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;<br />
&lt; xsl:template match="/"&gt;<br />
 &#038;nbsp   &lt; html&gt;<br />
  &#038;nbsp   &#038;nbsp       &lt; head&gt;<br />
   &#038;nbsp   &#038;nbsp   &#038;nbsp         &lt; title&gt;&lt; xsl:value-of select="page/title"/&gt;&lt; /title&gt;<br />
     &#038;nbsp   &#038;nbsp    &lt; /head&gt;<br />
    &#038;nbsp   &#038;nbsp     &lt; body&gt;<br />
    &#038;nbsp   &#038;nbsp     &lt; xsl:for-each select="books/book"&gt;<br />
      &#038;nbsp   &#038;nbsp   &#038;nbsp     &lt; small&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; u&gt;&lt; b&gt;&lt; xsl:value-of select="title"/&gt;&lt; /b&gt;&lt; /u&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; b&gt;&lt; xsl:text&gt;Author: &lt; /xsl:text&gt;&lt; /b&gt;&lt; xsl:value-of select="author"/&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; b&gt;&lt; xsl:text&gt;Price: &lt; /xsl:text&gt;&lt; /b&gt;&lt; xsl:value-of select="price"/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; xsl:if test="special &gt; 0"&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp              &lt; b&gt;&lt; xsl:text&gt; On Sale For: &lt; /xsl:text&gt;&lt; xsl:value-of select="special"/&gt;&lt; /b&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; /xsl:if&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; b&gt;&lt; xsl:text&gt;Paperback: &lt; /xsl:text&gt;&lt; /b&gt;&lt; xsl:value-of select="size"/&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; b&gt;&lt; xsl:text&gt;Publisher: &lt; /xsl:text&gt;&lt; /b&gt;&lt; xsl:value-of select="publisher"/&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; b&gt;&lt; xsl:text&gt;ISBN: &lt; /xsl:text&gt;&lt; /b&gt;&lt; xsl:value-of select="isbn"/&gt;&lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp   &#038;nbsp            &lt; br/&gt;<br />
 &#038;nbsp   &#038;nbsp   &#038;nbsp          &lt; /small&gt;<br />
 &#038;nbsp   &#038;nbsp        &lt; /xsl:for-each&gt;<br />
 &#038;nbsp   &#038;nbsp        &lt; /body&gt;<br />
 &#038;nbsp      &lt; /html&gt;<br />
&lt; /xsl:template&gt;<br />
&lt; /xsl:stylesheet&gt;</code></p>
<p>Output:<br />
<center><img src="http://images.ientrymail.com/wirelesspronews/0926figure3.gif"></center></p>
<p><b>VXML</b></p>
<p>PHP Source Code:</p>
<pre> &lt;?php
include_once("./xslt.class.php");
$xslt = new Xslt("c://data//books_vxml.xsl", "c://data//books.xml");
header("Content-type: text/xml");
print ($xslt->transform());
?&gt;</pre>
<p><b>XSL File</b></p>
<p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;<br />
&lt;xsl:template match="/"&gt;<br />
&#038;nbsp     &lt;vxml version="2.0"&gt;<br />
  &#038;nbsp  &#038;nbsp       &lt;form id="intro"&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp       &lt;block&gt;<br />
     &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp      &lt;xsl:for-each select="books/book"&gt;<br />
  &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp          &lt;xsl:value-of select="title"/&gt;&lt;break size="large"/&gt;&lt;break size="large"/&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp        &lt;xsl:text&gt;Author &lt;/xsl:text&gt;&lt;xsl:value-of select="author"/&gt;&lt;break size="large"/&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp        &lt;xsl:text&gt;Price &lt;/xsl:text&gt;&lt;xsl:value-of select="price"/&gt;&lt;break size="large"/&gt;<br />
   &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp         &lt;xsl:if test="special &gt; 0"&gt;<br />
     &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp         &lt;xsl:text&gt;On Sale For &lt;/xsl:text&gt;&lt;xsl:value-of select="special"/&gt;&lt;break size="large"/&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp        &lt;/xsl:if&gt;<br />
  &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp          &lt;xsl:text&gt;Paperback: &lt;/xsl:text&gt;&lt;xsl:value-of select="size"/&gt;&lt;break size="large"/&gt;<br />
     &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp       &lt;xsl:text&gt;Publisher: &lt;/xsl:text&gt;&lt;xsl:value-of select="publisher"/&gt;&lt;break size="large"/&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp        &lt;xsl:text&gt;ISBN: &lt;/xsl:text&gt;&lt;xsl:value-of select="isbn"/&gt;&lt;break size="large"/&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp  &#038;nbsp         &lt;/xsl:for-each&gt;<br />
    &#038;nbsp  &#038;nbsp  &#038;nbsp       &lt;/block&gt;<br />
   &#038;nbsp  &#038;nbsp      &lt;/form&gt;<br />
   &#038;nbsp    &lt;/vxml&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p>
<p><b>Output:</b></p>
<p>It is unlikely you will have the voice-recognition technology equipment to run the VXML example.  However, you can visit one of the VoiceXML providers such as VoiceGenie.com or Tellme.com.  As well in this demonstration the output will stream the entire information from start to finish.  When developing VoiceXML applications you should tailor the application towards voice interaction.  </p>
<p>In this example, it would probably be better to list out the titles of the books in menu like fashion, possible as abbreviated titles.  From there the user should select an option and thereafter the details of the book would be told to the user.  The implementation of this is beyond the scope of this article.</p>
<p><b>The Benefits</b></p>
<p>Because we are using the same content in all cases, whether it is HTML, WML, cHTML or VXML the same XML data file is used.  If additional books are added, books need to be removed or changes need to be made such as sales price all you really have to do is change the data in the XML file.  As well this provides another layer of abstraction between the presentation layer and server-side code.  </p>
<p>It keeps your code a lot cleaner rather then having several different files or several if statements in your PHP code to output the appropriate content for the appropriate viewer.  As well it prevents you from inserting difficult to find and difficult to debug PHP code in all the different files for all the different devices being supported.</p>
<p>However, you will notice the Sale price is only displayed based upon the if statement in the XSL stylesheet, if this for some reason needed to be changed you would have to make the change in each XSL stylesheet.  To avoid this, simply generate dynamic XML files with PHP and have your logic in the PHP code determine what goes into the XML file.  </p>
<p>As well you can then use PHP to determine which appropriate pre-defined XSL stylesheet to use.  This way your XML files are purely used as means of holding data in meaningful structure without any processing logic at all.</p>
<p>Furthermore, you have not only saved maintenance time but as well reduced the amount of effort needed if you were to support other features such as:</p>
<p> Reports in  PDF format<br />
 RSS feeds<br />
 WebServices<br />
 SVG<br />
 ChessML<br />
 AvantGo<br />
 AIML<br />
 XHTML<br />
 HDML</p>
<p>the list goes on and on.</p>
<p>Web Services is especially important when you want to start sharing the same information to other businesses or simply to other devices that are not script based such as SymbianOS devices, Palm, J2ME enabled devices and SmartPhones.   This is because you are working with an agreed upon industry standard largely based on XML.</p>
<p><b>Summary </b></p>
<p>Even though there were several different types of technologies being used the over all goal was to demonstrate XSL is indeed beneficial when providing the same content to several different types of devices.  As well if you aren&#8217;t familiar with some of the above wireless technologies that this article has now peeked your interests into something new.</p>
<p>Jason is a wireless and open source developer enthusiast who enjoys creating synergy and sharing knowledge in the software development world. To learn more about him visit his personal site at http://www.jasonlam604.com/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/php-xml-and-xsl-for-wireless-content-2003-11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding and displaying data easily via ASP and XML/XSL</title>
		<link>http://www.webpronews.com/adding-and-displaying-data-easily-via-asp-and-xmlxsl-2003-08</link>
		<comments>http://www.webpronews.com/adding-and-displaying-data-easily-via-asp-and-xmlxsl-2003-08#comments</comments>
		<pubDate>Wed, 13 Aug 2003 18:17:26 +0000</pubDate>
		<dc:creator>Sonu Kapoor</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[VAR]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=6917</guid>
		<description><![CDATA[Storing and displaying data is a  common and essential task, if you are working with Applications. It doesn't matter whether you are working with desktop Applications or WebApplications.
]]></description>
			<content:encoded><![CDATA[<p>Storing and displaying data is a  common and essential task, if you are working with Applications. It doesn&#8217;t matter whether you are working with desktop Applications or WebApplications.</p>
<p>The saving and displaying process is nearly always required. In this article I will show you how you can easily use an ASP form to add data into a XML file and how you can retrieve this data to display it in a well formed table. We will create an example ASP page, in which the user will be able to enter his Name, Age, Gender and a Postalcode. This data will be stored in a XML file. To display the data we will use XSL. The example ASP page and the resulting table look like this:</p>
<p><img border="0" src="http://images.ientrymail.com/webproasp/form.gif" width="423" height="297"></p>
<p>Its has always been important for me to divide the ASP Page in two parts and I would suggest you to do the same. Some people are mixing the asp and html code, but I would not recommend it to you. But sometimes it isn`t possible to spilt the ASP Page in two parts, in this case you will need to find your own and best suitable way. But anyway, try it! Here an image of the structure how my ASP page always looks like:</p>
<p><img border="0" src="http://images.ientrymail.com/webproasp/2Parts.gif" width="358" height="147"></p>
<p>The first part contains a simple Form, and the second part contains the  ASP Code which will do the saving for us. For a better understanding we will start with the Form.</p>
<p><b><u>Part I the Form:</u></b></p>
<p>You can create any simple form, with any controls you like. In addition to the other controls, we also need a submit and a reset button.</p>
<p>In my example I have created a simple form called <b>frmPerson</b>, which contains three textfields and a drop down field.</p>
<p>This form will use the post method to process the entered data.</p>
<p><u><b>Here is the code of my form:</b></u></font></p>
<pre>&lt;form action=&quot;VerifyPerson.asp&quot; method=&quot;post&quot; name=&quot;frmPerson&quot; id=&quot;frmPerson&quot;&gt;
&lt;INPUT name=Name&gt;
&lt;INPUT name=Age&gt;
&lt;SELECT style=&quot;WIDTH: 154px&quot; name=Gender&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;OPTION value=Male selected&gt;Male&lt;/OPTION&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;OPTION value=Female&gt;Female&lt;/OPTION&gt;
&lt;/SELECT&gt;
&lt;INPUT name=Postalcode&gt;
&lt;INPUT type=submit value=Submit name=submit&gt;&lt;INPUT type=reset value=Reset name=reset&gt;
&lt;/form&gt;
</pre>
<p>It is very important to give each used TAG which will hold the data, a variable name.</p>
<p>For Example: The name textfield &lt;INPUT name=<Font color=red><u><b>Name</b></u></Font>&gt; contains the variable <Font color=red><u><b>Name</b></u></Font>. In order to retrieve the data from the form we will use this and other variables in the next ASP paragraph.</p>
<p>You dont need to write down this code, because the examples covered in this Article are available for download. To get familar with ASP and XML I suggest you download the examples and try to work with it. To give the form a better and professional look I have included a table with some effects, so dont get worried about the whole code. As you can see this was the first <b>easy</b> part of the ASP page and the second part will be even easier.</p>
<p><b><u>Part II the ASP code:</u></b></p>
<p>In this paragraph I will show you in 7 easy steps how you can retrieve the data from the form and how you can save the data to a XML<br />
file.</p>
<p>1. The first step is to check whether the user has pressed the <b>submit</b> button or not! For this we will use the JScript function <b>count</b>.</p>
<pre>
var submit = Request.Form(&quot;submit&quot;).Count;
if( submit &gt; 0 ){
  // The user has pressed the submit button
  // So the code to save the data will take place here.
}
else{
  // We could also place our form in this part of code, which must be then written in JScript.
  //But I would not recommend that !!!
}
</pre>
<p>2. Now we need to retrieve the data from the form. This data will be stored in some variables. To retrieve the data we will use the <b>Request.Form(&quot;variable_name&quot;);</b><br />
function. So let us create 4 variables and retrieve the required data.</p>
<pre>
var name = Request.Form(&quot;Name&quot;);
var age = Request.Form(&quot;Age&quot;);
var gender	= Request.Form(&quot;Gender&quot;);
var pcode	= Request.Form(&quot;PostalCode&quot;);
</pre>
<p>
3.The third step is to check whether the user has entered some data, or not. For this we can just check whether the variables in step 2 are still empty or not.</p>
<pre>
var error = &quot;&quot;;
if ( name == &quot;&quot; )
  error = &quot;Name &quot;;
if ( age == &quot;&quot; )
  error += &quot;Age &quot;;
if ( pcode == &quot;&quot;)
  error += &quot;PostalCode &quot;;
</pre>
<p>4. In step 3 we have saved the result in the var <b>error</b>. Now we need to check, if &quot;error&quot; consists some data or not. If yes, then we have found an error, and we will display it. If not, then we will start with the saving procedure.</p>
<pre>
if(error!=&quot;&quot;){
  //We have found an error, so display this to the user!
  Response.Write(&quot;Please enter the following data:&lt;br&gt;&quot;);
  Response.Write(&lt;b&gt;);
  Response.Write(error);
  Response.Write(&quot;&lt;/b&gt;&quot;);
}
else{
//Everything is fine, so let us start to save the data.
</pre>
<p>5. Now we have done the nessesary checks and can start with saving the data. For that we will load the <b>Person.xml</b> in a xmlDocument. Then we will load the current node list to get the current root node. To get the current root node, we will use the function <b>xmlDoc.getElementsByTagName</b>. After that we need to create the required nodes, this can be achived with the function <b>xmlDoc.createElement(&quot;AnyNodeName&quot;)</b>. At last we only need to save the entered data from the form to the approriate xml variables. So here is the code, how it could look like:</p>
<pre>
.
.
.
else{
  // here we are loading the requried xml file
  var xmlDoc=Server.CreateObject(&quot;MICROSOFT.FreeThreadedXMLDOM&quot;);
  xmlDoc.async=&quot;false&quot;;
  xmlDoc.load(Server.MapPath(&quot;Person.xml&quot;));
  // Get the current root
  var nodeList = xmlDoc.getElementsByTagName(&quot;PersonList&quot;);
  if(nodeList.length &gt; 0){
    var parentNode = nodeList(0) ;
    // Create the required nodes
    var personNode = xmlDoc.createElement(&quot;Person&quot;);
    var nameNode   = xmlDoc.createElement(&quot;Name&quot;);
    var ageNode    = xmlDoc.createElement(&quot;Age&quot;);
    var genderNode = xmlDoc.createElement(&quot;Gender&quot;);
    var pcodeNode  = xmlDoc.createElement(&quot;PostalCode&quot;);
    // Assign the variables, which we have retrieved in step 2 to the xml variables.
    nameNode.text  = name;
    ageNode.text   = age;
    genderNode.text= gender;
    pcodeNode.text = pcode;
	.
	.
	.
</pre>
<p>6. We have done nearly everything to save the data, but there are still two steps left. In this step we will append the created nodes to the parent node. This can be done with the function <b>parentNode.appendChild(&quot;personNode&quot;);</b></p>
<pre>
   .
   .
   .
   parentNode.appendChild(personNode);
   personNode.appendChild(nameNode);
   personNode.appendChild(ageNode);
   personNode.appendChild(genderNode);
   personNode.appendChild(pcodeNode);
   .
   .
   .
</pre>
<p>7. Finally we only need to save the nodes to the xml file. For this you can use the function <b>xmlDoc.save(Server.MapPath(&quot;Person.xml&quot;));</b>.</p>
<pre>
   // 7) Now save the nodes to the file
   xmlDoc.save(Server.MapPath(&quot;Person.xml&quot;));
</pre>
<p><u><b>XSL:</b></u></p>
<p>With this example you can save easily the data of any Person into a XML file.&nbsp;Right now we have only seen how to save the data, but how do we display it ? The answer is again easy. We will use ASP and XSL to display the data. The first thing you need to do is to load the XML file, this can be achieved with a XML Parser. The XML parser from Microsoft is available directly with Internet Explorer 5.0. After you have loaded the XML file in the document Object, you can retrieve the XML data with the help of a DOM Object. In the same way you must load the XSL file.&nbsp;</p>
<pre>
   // This part is used to display the data&nbsp;
   var objXMLDoc = Server.CreateObject(&quot;MICROSOFT.FreeThreadedXMLDOM&quot;);
   objXMLDoc.async = false;
   objXMLDoc.load(Server.MapPath(&quot;person.xml&quot;));
   var xsl=Server.CreateObject(&quot;MICROSOFT.FreeThreadedXMLDOM&quot;);
   xsl.async = false;
   xsl.load(Server.MapPath(&quot;person.xsl&quot;));
</pre>
<p>Now you have loaded both files, each one DOM Object. Now you only need to create a query which will select the nodes for us. Of course we could select some specific nodes, but for our needs we will just select the root node, so all other nodes will be selected automatically.</p>
<pre>
   var xmlQuery=&quot;//Person&quot;;
   var docHeadlines=objXMLDoc.documentElement.selectNodes(xmlQuery);
</pre>
<p>After that you only need to iterate through the nodes to display each stored item.</p>
<pre>
   var numNodes;
   numNodes=docHeadlines.length;
   var nn;
   for(var i=0;i&lt;numNodes;i++){
     nn = docHeadlines.nextNode();
     Response.Write(nn.transformNode(xsl));
   }
</pre>
<p><u><b>Conclusion:</b></u></p>
<p>That&#8217;s it ! Now you have created a fully functional system which can save, read and display data from a form. You have learned the advantages of ASP,XML and XSL. To practice a little bit more, I suggest you to modify the ASP page, to create your own Address book. Once you have mastered and created your own ASP page you will understand much more.</p>
<p><a href="http://images.ientrymail.com/webproasp/example.zip">Download examples</a></p>
<p>First published at <a href="http://www.sitepoint.com">SitePoint.com</a></p>
<p>Codefinger was founded 2000 by Sonu Kapoor. Sonu has studied E-Commerce in India and currently lives in Germany. After graduation he worked for several companies in Germany. He currently works as a Network Consultant and Software Developer. He has written many applications in various programming languages like VC++, ASP, ASP.NET, XML or XSL. Besides his passion for developing applications, Sonu writes articles for several major websites like <a href="http://www.developer.com">Developer.com</a>. He also works as a freelancer for <a href="http://www.codeguru.com/">CodeGuru</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/adding-and-displaying-data-easily-via-asp-and-xmlxsl-2003-08/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve quick results with ASP/XML and XSL</title>
		<link>http://www.webpronews.com/retrieve-quick-results-with-aspxml-and-xsl-2003-06</link>
		<comments>http://www.webpronews.com/retrieve-quick-results-with-aspxml-and-xsl-2003-06#comments</comments>
		<pubDate>Mon, 30 Jun 2003 14:44:50 +0000</pubDate>
		<dc:creator>Sonu Kapoor</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>

		<guid isPermaLink="false">http://www.webpronews.com/?p=5363</guid>
		<description><![CDATA[Recently I was working on a new Project about ASP along with XML/XSL. I recognized that ASP with XML is a very powerful tool and that was the main reason I wrote this article.
]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a new Project about ASP along with XML/XSL. I recognized that ASP with XML is a very powerful tool and that was the main reason I wrote this article.</p>
<p>In this article, I will explain how to retrieve XML elements with ASP and how to retrieve <b>specific</b> values from XML files with the help of XPath. I will also introduce the usage of XSL.</p>
<p><b>XML:</b></p>
<p>XML ( Extensible Markup Language ) is designed to hold data in user defined tags. XML doesn&#8217;t contain any predefined tags, you must create your own tags, which can hold the required data. Its important to understand that XML does not perform any task by itself. Its only usage is to store information that can be sent in a portable way. You can imagine an XML file like a plain text database file. The XML-tags are similar with the tables of a database. In a database you will also have to define your tables, which will hold your data.</p>
<p>Here is a sample of a simple XML file:</p>
<p>-=<code2>=-</p>
<p>This way, you could enter any number of &#8216;Person&#8217; records you like. To load and display the XML data you will need an XML Parser. The Microsoft XML Parser is a COM component and is directly available with IE 5.0. Once you have loaded your XML file in the document object, you can easily retrieve the data via a DOM object. Here is a snippet of code which will display the data using ASP. </p>
<p>-=<code3>=-</p>
<p><b>XPath:</b></p>
<p>The above example will display each and every person. In order to retrieve a specific &#8216;Person&#8217; or to display the &#8216;Person&#8217;s name only we can make use of XPath. You can compare XPath with the <b>select</b> statement of a database. We can use the XPath for XML the same way we would use the select syntax to get a specific record from a database. You can say that XPath is the answer, if you need to make a specific selection. I will use the same example as above to show you the usage of XPath.</p>
<p>-=<code4>=-</p>
<p><b>XSL:</b></p>
<p>By now, you have seen how to load data and how to select specific data. But what if we need to display the data in a table or in a form, so that it looks much more user friendly than now? For this purpose we will use XSL. XSL is a language to transform XML into HTML code. XSL will give your XML data a user friendly look. But XSL can do much more. With XSL you will also be able to sort and filter of any XML data. We will extend our example to see the usage of XSL.</p>
<p><b>NOTE: XSL in not compatible with IE 5.0. IE6 fully supports XSL.</b></p>
<p><b>Person.xsl </b></p>
<p>-=<code5>=-</p>
<p><b>Here your modified XML file: </b></p>
<p>-=<code6>=-</p>
<p>After completing the project, I have learned how to use XML with ASP, how to use XPath and the power of XSL. I hope my article provided you with some useful information, too.</p>
<p><b><a href="http://images.ientrymail.com/xmlpronews/person.zip">Download the example</a></b></p>
<p>Article appeared at <a href="http://www.codefinger.de">Codefinger.de</a></p>
<p>Codefinger was founded 2000 by Sonu Kapoor. Sonu has studied E-Commerce in India and currently lives in Germany. After graduation he worked for several companies in Germany. He currently works as a Network Consultant and Software Developer. He has written many applications in various programming languages like VC++, ASP, ASP.NET, XML or XSL. Besides his passion for developing applications, Sonu writes articles for several major websites like <a href="http://www.developer.com">Developer.com</a>. He also works as a freelancer for <a href="http://www.codeguru.com/">CodeGuru</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webpronews.com/retrieve-quick-results-with-aspxml-and-xsl-2003-06/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 1/57 queries in 0.025 seconds using memcached
Object Caching 633/776 objects using memcached

Served from: webpronews.com @ 2012-02-12 11:40:22 -->
