a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

基于XSLT調試的相關問題

2020-01-24 03:21:30
字體:
來源:轉載
供稿:網友

新建控制臺程序CAStudy.在應用程序中,添加books.xml,belowAvg.xsl 代碼分別如下:

books.xml

<?xml version='1.0'?>

<!-- This file represents a fragment of a book store inventory database -->

<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>

books.xml一看就知道是一個bookstore,里面包含了三個book. 每個book都會有一些attribute和property.例如genre,publicationdate,ISBN 就是attribute.而諸如title,author,price 就是book的property 了。

belowAvg.xsl:

<?xml version='1.0'?>

<xsl:stylesheet version="1.0"

      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" encoding="utf-8"/>

  <xsl:template match="/">

    <xsl:variable name="bookCount" select="count(/bookstore/book)"/>

    <xsl:variable name="bookTotal" select="sum(/bookstore/book/price)"/>

    <xsl:variable name="bookAverage" select="$bookTotal div $bookCount"/>

    <books>

      <!--Books That Cost Below Average-->

      <xsl:for-each select="/bookstore/book">

        <xsl:if test="price < $bookAverage">

          <xsl:copy-of select="."/>

        </xsl:if>

      </xsl:for-each>

    </books>

  </xsl:template>

</xsl:stylesheet>

belowAvg.xsl:名字就代表了,小于平均值的xsl.

XSLT: 可擴展樣式表語言轉換Extensible Stylesheet Transformation (XSLT)

這個belowAvg.xsl 主要就是將book.xml 中小于平均值的那些book找出來,輸出成xml

match=”/”:這樣就可以匹配三個book節點了。

接著聲明3個變量,bookCount,bookTotal,在第三個變量中使用$符號來引用前面聲明的變量得到平均值。

接著進行for-each的循環,在循環里面進行if 測試,測試的條件是price < $bookAverage. < xml里面是< lt less than 的意思,同理> xml里面是> gt 就是great than的意思。

接著進行copy-of 操作,”.” 代表的就是self::node(),也就是book節點。

image 

調試xslt 有兩種方式:

第一種:使用VS

打開xsl,可以發現菜單多了XML,點擊XML菜單的調試XSLT,然后選擇book.xml 就可以進行調試了。

image

同樣F9設置斷點,

第二種方法:使用代碼.

class XmlXsltDemo

{

    private const string sourceFile = @"books.xml";

    private const string stylesheet = @"belowAvg.xsl";

    private const string outputFile = @"output.xml";

    public static void Main()

    {

        // Enable XSLT debugging.

        XslCompiledTransform xslt = new XslCompiledTransform(true);

        // Compile the style sheet.

        xslt.Load(stylesheet);

        // Execute the XSLT transform.

        FileStream outputStream = new FileStream(outputFile, FileMode.Append);

        xslt.Transform(sourceFile, null, outputStream);

    }

}

在這里由于使用的是相對路徑,所以要將books.xml和belowAvg.xsl 屬性修改如下:

image

還要將XslCompiledTransform xslt = new XslCompiledTransform(true);

參數傳遞為true,代表enableDebug.

就可以看到如下界面了:

image 

使用代碼調試的話,不需要設置斷點,只要enableDebug為true的話,會自動在xsl中中斷。

本人猜測估計是調用了Debugger.Break() 方法。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中文字幕在线一区观看 | 人人看人人爽 | 久久合| 日韩一区二区在线电影 | 久久久毛片 | 国产精品日韩欧美一区二区三区 | 大黑人交xxx极品hd | 北条麻妃国产九九九精品小说 | 欧美精品黄| 免费在线看a | 国产日韩欧美一区 | 亚洲欧美另类久久久精品2019 | 一色视频 | 北条麻妃99精品青青久久主播 | 国产精品电影久久 | 久久久精品一区二区 | 久久久精品国产 | 国产中文字幕一区二区三区 | 成人v片| 国产高清一区二区三区 | 在线欧美成人 | 欧美三级黄 | 亚洲久久在线 | 久久久久久国产免费视网址 | 97久久超碰国产精品电影 | 中文字幕国产视频 | av观看| 亚洲精选一区 | 91网站在线播放 | 欧美 日韩 中文 | 一区二区三区在线 | 亚洲人成人一区二区在线观看 | 亚洲男人av | 美女久久久 | 国产伦精品一区二区三区照片91 | 亚洲一级黄色片 | 九九综合九九综合 | 成人在线观| 久久亚洲国产精品日日av夜夜 | 有码在线 | 久久免费精品 |