亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于XSLT調(diào)試的相關問題

 更新時間:2013年05月13日 12:49:40   作者:  
本篇文章是對XSLT調(diào)試的相關問題進行了詳細的分析介紹,需要的朋友參考下

新建控制臺程序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 &lt; $bookAverage">

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

        </xsl:if>

      </xsl:for-each>

    </books>

  </xsl:template>

</xsl:stylesheet>

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

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

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

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

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

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

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

image 

調(diào)試xslt 有兩種方式:

第一種:使用VS

打開xsl,可以發(fā)現(xiàn)菜單多了XML,點擊XML菜單的調(diào)試XSLT,然后選擇book.xml 就可以進行調(diào)試了。

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

參數(shù)傳遞為true,代表enableDebug.

就可以看到如下界面了:

image 

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

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

相關文章

最新評論