日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

使用XSLT转换XML数据并传递参数

發(fā)布時間:2024/1/17 asp.net 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用XSLT转换XML数据并传递参数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.首先要做xsd文檔中定義一個全局變量 使用<xsl:param />標(biāo)簽進(jìn)行聲明

2.C#代碼中使用XslCompiledTransform中的AddParam方法添加參數(shù),

? ?XslCompiledTransform 類的Transform方法中傳遞XslCompiledTransform對象

?

XML:

? ? ??

View Code <?xml version='1.0'?>
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>

XSL:

View Code <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!--設(shè)置參數(shù)-->
<xsl:param name="discount" select=".10"/>
<xsl:template match="bookstore">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>ISBN</TD>
<TD>Title</TD>
<TD>Price</TD>
<TD>Calculated Discount</TD>
</TR>
<xsl:apply-templates select="book"/>
</TABLE>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="book">
<TR>
<TD>
<xsl:value-of select="@ISBN"/>
</TD>
<TD>
<xsl:value-of select="title"/>
</TD>
<TD>
<xsl:value-of select="price"/>
</TD>
<TD>
<xsl:value-of select="price * ($discount)"/>
</TD>
</TR>
</xsl:template>
</xsl:stylesheet>

C# 代碼:

??

View Code string xmlpath = Request.PhysicalApplicationPath +
@"\App_Data\Books.xml";
string xslpath = Request.PhysicalApplicationPath +
@"\App_Data\Books.xsl";
XPathDocument xpathDoc = new XPathDocument(xmlpath);
XslCompiledTransform transform = new XslCompiledTransform();
XsltArgumentList argsList = new XsltArgumentList();
argsList.AddParam("discount","",".15");
transform.Load(xslpath);
transform.Transform(xpathDoc,argsList, Response.Output);

?

源代碼

?

轉(zhuǎn)載于:https://www.cnblogs.com/WilliamJiang/archive/2012/03/03/2378543.html

總結(jié)

以上是生活随笔為你收集整理的使用XSLT转换XML数据并传递参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。