XML transformation with parameter : Transform « XML « ASP.Net

ASP.Net
1. ADO.net Database
2. Asp Control
3. Collections
4. Components
5. Data Binding
6. Development
7. HTML Control
8. Mobile Control
9. Page
10. Request
11. Response
12. Server
13. Session Cookie
14. User Control and Master Page
15. Validation by Control
16. Validation by Function
17. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » XML » Transform 
XML transformation with parameter

<%--
Code Revised from
       
Professional ASP.NET 2.0 XML (Programmer to Programmer) (Paperback)
by Thiru Thangarathinam 

# Publisher: Wrox (January 182006)
# Language: English
# ISBN: 0764596772
--%>
       
       
       
       
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>

<script runat="server">                
    void Page_Load(object sender, System.EventArgs e)
  {
        string xmlPath = MapPath("BooksWithStyle.xml");
        string xslPath = MapPath("Books_with_parameters.xsl");      
      XPathDocument xpathDoc = new XPathDocument(xmlPath);      
        XslCompiledTransform transform = new XslCompiledTransform();
        XsltArgumentList argsList = new XsltArgumentList();
        argsList.AddParam("discount"""".15");                 
        //Load the XSL stylsheet into the XslCompiledTransform object
        transform.Load(xslPath);                
        transform.Transform(xpathDoc, argsList, Response.Output);            
    }        
</script>


<%--BooksWithStype.xml
<?xml version='1.0'?>
<bookstore>
  <book genre="A">
    <title>title 1</title>
    <author>
      <first-name>A</first-name>
      <last-name>B</last-name>
    </author>
    <price>99.99</price>
  </book>
  <book genre="B">
    <title>title 2</title>
    <author>
      <first-name>B</first-name>
      <last-name>C</last-name>
    </author>
    <price>11.99</price>
  </book>
</bookstore>

--%>


<%--Books_with_parameters.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" />
  <!-- Set the Discount parameter -->
  <xsl:param name="discount" select=".10" />
  <xsl:template match="/">
    <html>
      <title>XSL Transformation</title>
      <body>
        <h2>My Book Collection</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th align="left">Title</th>
            <th align="left">Price</th>
            <th align="left">Calculated Discount</th>
          </tr>
          <xsl:for-each select="bookstore/book">
            <tr>
              <td>
                <xsl:value-of select="title"/>
              </td>
              <td>
                <xsl:value-of select="price"/>
              </td>
              <td>
                <xsl:value-of select="price * ($discount)"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
--%>
           
       
Related examples in the same category
1. Applying XSL Transformation on an XmlDataSource Control
2. Simplest XML transform
3. XML transformation with extension
4. XML transformation with script in the xls
5. Passing a Nodeset as a Parameter in XML transformation
6. Load tranformation file from the web
ww_w.___j_a__v___a__2s.c__om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.