13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In the first template, the context node is , but at a certa<strong>in</strong> po<strong>in</strong>t, we need toaccess a sibl<strong>in</strong>g node—the node. The XPath syntax <strong>in</strong>cludes the doubledotsymbol (..), which is a shortcut <strong>for</strong> the parent of the current context node. (SeeChapter 6.)The f<strong>in</strong>al HTML output <strong>for</strong> the source <strong>XML</strong> document is shown Figure 7-3.Figure 7-3: The HTML page generated from a source <strong>XML</strong> file.To display the HTML output as pla<strong>in</strong> text, you must per<strong>for</strong>m the trans<strong>for</strong>mationprogrammatically, us<strong>in</strong>g either the MS<strong>XML</strong> object model or the newest .<strong>NET</strong>Framework classes. Alternatively, you can view the output us<strong>in</strong>g a specialized browserwith the direct brows<strong>in</strong>g functionality. <strong>Microsoft</strong> Internet Explorer has provided thiscapability s<strong>in</strong>ce version 5.0.L<strong>in</strong>k<strong>in</strong>g the Style Sheet to the HTML PageInternet Explorer applies a silent and automatic trans<strong>for</strong>mation to all <strong>XML</strong> documentsyou view through it. However, an <strong>XML</strong> document can override the default InternetExplorer style sheet by us<strong>in</strong>g a process<strong>in</strong>g <strong>in</strong>struction that simply l<strong>in</strong>ks an XSLT script.The follow<strong>in</strong>g code demonstrates how to add the style sheet from the previous section(emplist.xsl) to the source file (data.xml) so that double-click<strong>in</strong>g it generates the outputshown <strong>in</strong> Figure 7-3. A style sheet can have either a .xsl or a .xml extension.You register a style sheet with an <strong>XML</strong> document us<strong>in</strong>g a process<strong>in</strong>g <strong>in</strong>struction with acouple of attributes: type and href. The type attribute must be set to the str<strong>in</strong>g text/xsl.The href attribute <strong>in</strong>stead references the URL of the XSLT script. If you <strong>in</strong>sert more thanone process<strong>in</strong>g <strong>in</strong>struction <strong>for</strong> XSLT scripts, only the f<strong>in</strong>al <strong>in</strong>struction will be considered.Call<strong>in</strong>g TemplatesThe previous example used exclusively to per<strong>for</strong>m templatebasedtrans<strong>for</strong>mations. When you know that only one template applies to a given block246

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!