小編給大家分享一下如何通過XSLT將xml轉(zhuǎn)換為html,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
c#使用XSLT將xml文檔轉(zhuǎn)換為html文檔 使用xslt可以將xml文檔轉(zhuǎn)成html,如下c#函數(shù): 需要引用下面的命名空間: using System.Xml; using System.Xml.Xsl; 方法實現(xiàn): public static string ConvertXML(XmlDocument InputXMLDocument, string XSLTFilePath , XsltArgumentList XSLTArgs) { System.IO.StringWriter sw = new System.IO.StringWriter(); XslCompiledTransform xslTrans = new XslCompiledTransform(); xslTrans.Load(XSLTFilePath); xslTrans.Transform(InputXMLDocument.CreateNavigator(), XSLTArgs, sw); return sw.ToString(); } 示例xml文件如下: <?xml version="1.0" encoding="utf-8" ?> <sexystars> <category name="Bollywood"> <sexystar name="Antra mali" /> <sexystar name="Deepika Padukone" /> <sexystar name="Mandira Bedi" /> </category> <category name="Hollywood"> <sexystar name="Jennifer Lopez" /> <sexystar name="Jessica Alba" /> </category> </sexystars> 示例xslt文件如下: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="sexystars"> <p> <xsl:apply-templates select="category" /> </p> </xsl:template> <xsl:template match="category"> <h3> <xsl:value-of select="@name"/> </h3> <ul> <xsl:apply-templates select="sexystar" /> </ul> </xsl:template> <xsl:template match="sexystar"> <li> <xsl:value-of select="@name"/> </li> </xsl:template> </xsl:stylesheet> 調(diào)用的c#代碼: XmlDocument xDoc=new XmlDocument(); xDoc.Load(@"C:\sample.xml"); string returnhtml = ConvertXML(xDoc, @"C:\sample.xslt", new XsltArgumentList()); 將輸入如下html: <p> <h3>Bollywood</h3> <ul> <li>Antra mali</li> <li>Deepika Padukone</li> <li>Mandira Bedi</li> </ul> <h3>Hollywood</h3> <ul> <li>Jennifer Lopez</li> <li>Jessica Alba</li> </ul> </p>
以上是“如何通過XSLT將xml轉(zhuǎn)換為html”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設計公司行業(yè)資訊頻道!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站標題:如何通過XSLT將xml轉(zhuǎn)換為html-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://chinadenli.net/article10/cdhido.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設、做網(wǎng)站、網(wǎng)頁設計公司、外貿(mào)建站、動態(tài)網(wǎng)站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容