欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

新建控制臺程序CAStudy.在應(yīng)用程序中,添加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: 可擴(kuò)展樣式表語言轉(zhuǎn)換Extensible Stylesheet Transformation (XSLT)

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

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

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

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

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

image 

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

第一種:使用VS

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

image

同樣F9設(shè)置斷點(diǎn),

第二種方法:使用代碼.

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)試的話,不需要設(shè)置斷點(diǎn),只要enableDebug為true的話,會自動在xsl中中斷。

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

相關(guān)文章

  • C#判斷頁面中的多個文本框輸入值是否有重復(fù)的實(shí)現(xiàn)方法

    C#判斷頁面中的多個文本框輸入值是否有重復(fù)的實(shí)現(xiàn)方法

    這篇文章主要介紹了C#判斷頁面中的多個文本框輸入值是否有重復(fù)的實(shí)現(xiàn)方法,是一個非常簡單實(shí)用的技巧,需要的朋友可以參考下
    2014-10-10
  • C#中WebBrowser.DocumentCompleted事件多次調(diào)用問題解決方法

    C#中WebBrowser.DocumentCompleted事件多次調(diào)用問題解決方法

    這篇文章主要介紹了C#中WebBrowser.DocumentCompleted事件多次調(diào)用問題解決方法,本文講解了3種情況和各自情況的解決方法,需要的朋友可以參考下
    2015-01-01
  • 基于C#實(shí)現(xiàn)俄羅斯方塊游戲

    基于C#實(shí)現(xiàn)俄羅斯方塊游戲

    這篇文章主要為大家詳細(xì)介紹了基于C#實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 最新評論