基于XSLT调试的相关问题

时间:2022-11-01 14:22:53 

新建控制台程序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节点了。

接着声明3个变量,bookCount,bookTotal,在第三个变量中使用$符号来引用前面声明的变量得到平均值。

接着进行for-each的循环,在循环里面进行if 测试,测试的条件是price < $bookAverage. < 在xml里面是&lt; lt 是less than 的意思,同理> 在xml里面是&gt; gt 就是great than的意思。

接着进行copy-of 操作,”.” 代表的就是self::node(),也就是book节点。

基于XSLT调试的相关问题 

调试xslt 有两种方式:

第一种:使用VS

打开xsl,可以发现菜单多了XML,点击XML菜单的调试XSLT,然后选择book.xml 就可以进行调试了。

基于XSLT调试的相关问题

同样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 属性修改如下:

基于XSLT调试的相关问题

还要将XslCompiledTransform xslt = new XslCompiledTransform(true);

参数传递为true,代表enableDebug.

就可以看到如下界面了:

基于XSLT调试的相关问题 

使用代码调试的话,不需要设置断点,只要enableDebug为true的话,会自动在xsl中中断。

本人猜测估计是调用了Debugger.Break() 方法。

标签:XSLT,调试
0
投稿

猜你喜欢

  • Android使用SQLite数据库的简单实例

    2022-03-04 13:52:50
  • 解决Druid动态数据源配置重复刷错误日志的问题

    2021-06-06 17:44:51
  • android手机获取唯一标识的方法

    2022-05-28 19:24:38
  • Intellij IDEA 2017新特性之Spring Boot相关特征介绍

    2023-06-22 15:13:02
  • SpringBoot如何实现定时任务示例详解

    2023-10-11 23:24:42
  • java swing实现QQ账号密码输入框

    2023-01-13 06:26:52
  • 一篇文章带你入门Java基本概念

    2023-11-26 01:17:08
  • maven基础教程——简单了解maven的特点与功能

    2023-09-07 03:43:02
  • 使用注解@Recover优化丑陋的循环详解

    2021-08-05 15:11:13
  • springboot配置项目启动后自动打开浏览器访问项目方式

    2023-10-05 07:33:09
  • SpringCloud远程服务调用三种方式及原理

    2023-10-16 07:21:19
  • Android 拦截返回键事件的实例详解

    2023-02-19 07:09:09
  • java判断各类型字符个数实例代码

    2022-01-22 16:39:15
  • c#中@的3种作用

    2022-03-23 17:18:07
  • Android实现定时任务及闹钟

    2023-05-20 13:34:45
  • C#利用DesignSurface如何实现简单的窗体设计器

    2023-10-18 18:43:28
  • C#静态方法的使用

    2022-05-19 06:45:09
  • 一文详解Java中流程控制语句

    2023-11-26 11:39:49
  • 基于Android中的 AutoCompleteTextView实现自动填充

    2023-04-02 07:11:36
  • java弹幕小游戏1.0版本

    2021-12-06 04:42:48
  • asp之家 软件编程 m.aspxhome.com