最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于XSLT調試的相關問題

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

新建控制臺程序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: 可擴展樣式表語言轉換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 

調試xslt 有兩種方式:

第一種:使用VS

打開xsl,可以發(fā)現菜單多了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() 方法。

相關文章

最新評論

东阳市| 德兴市| 新丰县| 黄陵县| 达孜县| 黔东| 光泽县| 武川县| 卓资县| 临漳县| 五莲县| 封丘县| 博白县| 华坪县| 岗巴县| 泾川县| 彰化市| 黔南| 策勒县| 柳州市| 田东县| 南溪县| 荥经县| 乌审旗| 仁怀市| 临颍县| 长武县| 大石桥市| 连江县| 华蓥市| 丹棱县| 淮阳县| 吉水县| 长兴县| 浠水县| 高雄县| 织金县| 丹棱县| 新巴尔虎右旗| 江陵县| 土默特左旗|