A XSLT Sample

2023-12-09 07:32
文章标签 sample xslt

本文主要是介绍A XSLT Sample,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

A XSLT Sample<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

(Wang hailong)

在中文网站到看到了不少关于XSLT的例子,可是大部分都属于入门性质的。下面给出一个XSLT的例子,说明XSLT的一些典型的用法。

XSLT1.0规范定义了document()函数,提供了初步的处理多个xml输入文件的功能。我们用这个功能来实现新旧xml文件的比较。

比如,我们有一个xml格式产品列表,列出一些关于XSLT处理的(Open Source)软件。

每隔一段时间,我们就更新一次产品列表。

下面的Product.1.xml是第一个产品列表。

product.1.xml

<?xml version="1.0" ?>

<product-root>

<!-- no histroy yet -->

<product-history/>

<product>

<product-id>001</product-id>

<product-name>Apache Xalan xslt</product-name>

<url>http://xml.apache.org/xalan-j/</url>

</product>

<product>

<product-id>002</product-id>

<product-name>saxon xslt</product-name>

<url>http://saxon.sourceforge.net/</url>

</product>

</product-root>

过了一段时间,产品列表更新为Product.2.xml。其中的product-history元素纪录以前的产品列表——Product.1.xml

product.2.xml

<?xml version="1.0" ?>

<product-root>

<!-- refer to last product list -->

<product-history>product.1.xml</product-history>

<product>

<product-id>001</product-id>

<product-name>Apache Xalan xslt</product-name>

<url>http://xml.apache.org/xalan-j/</url>

</product>

<product>

<product-id>002</product-id>

<product-name>saxon xslt</product-name>

<url>http://saxon.sourceforge.net/</url>

</product>

<product>

<product-id>003</product-id>

<product-name>XT xslt</product-name>

<url>http://www.4xt.org/</url>

</product>

<product>

<product-id>004</product-id>

<product-name>oasis xslt</product-name>

<url>http://www.oasis-open.org/</url>

</product>

</product-root>

我们用下面的xsl文件处理product.2.xml,查找新增加的product

product.diff.xsl

<?xml version="1.0"?>

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="product-root">

<difference>

<!-- get all history product-->

<xsl:variable name="history" select="document(product-history)//product" />

<!-- copy the product which is not in product history -->

<xsl:copy-of select="product[not(product-id=$history/product-id)]"/>

</difference>

</xsl:template>

</xsl:transform>

这个XSL文件虽然短小,却包括了XSLT很重要的一些特性和XPath的很典型的用法。因为product-history的内容是product.1.xml,所以document(product-history)取得上次产品列表product.1.xml的根元素。

document(product-history)//product取得product.1.xml的根元素下面所有的product元素。我们也可以写成document(product-history)/product-root/product,这种写法更加确定,指定只选取product-root元素下面的product

注意,product[not(product-id=$history/product-id)]表示“product-idhistory product-id都不相同product”;product[product-id!=$history/product-id]表示“product-id history product-id至少有一个不相同product”。

处理后的xml结果如下。

<?xml version="1.0" encoding="UTF-8"?>

<difference>

<product>

<product-id>003</product-id>

<product-name>XT xslt</product-name>

<url>http://www.4xt.org/</url>

</product>

<product>

<product-id>004</product-id>

<product-name>oasis xslt</product-name>

<url>http://www.oasis-open.org/</url>

</product>

</difference>

关于如何运行这个例子或其它的XSLT例子。首先,您需要一个XSLT转换工具。哪里获得XSLT转换工具呢?参见上面的产品列表product.2.xml,里面就包括了很好的XSLT转换工具。访问里面的url:-)

这篇关于A XSLT Sample的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/472980

相关文章

解决树莓派IOError: [Errno Invalid sample rate] -9997 采样率16K错误

树莓派在基于pyaudio录音的时候会提示如上错误,这主要是使用的树莓派声卡不支持当前的采用率,没关系,其实在alsa架构下我们可以通过声卡的插件实现转换。在树莓派下家目录创建一个声卡隐藏配置文件 .asoundrc。特别说明,不要在你的pyaudio里面设置打开声卡的编号因为下面的配置已经配置了。 1.安装 sudo apt-get install pulseaudio 2.在家目录创

理解Pytorch中的grid_sample函数

文章目录 函数签名参数说明示意图 grid_sample是 PyTorch 提供的一个函数,用于执行采样操作,通常用于图像处理。它允许通过给定的采样坐标从输入张量中获取相应的值。采样坐标可以包含小数,这时 grid_sample 会使用插值方法计算出对应的值。 torch.nn.functional.grid_sample 是 PyTorch 中用于从输入特征图中采样的函数

ATSS论文要点总结(Adaptive Training Sample Selection)

“ATSS” 全称为 “Adaptive Training Sample Selection”,意为自适应训练样本选择,相关论文的主要内容如下: 核心观点:在目标检测中,anchor-based 和 anchor-free 检测器性能差异的关键在于正负样本的定义方式。如果训练过程中使用相同的正负样本定义,两者性能将无明显差异。基于此,作者提出 ATSS 方法,根据目标的统计特征自动选择正负样本,

点云处理中阶 Sample Consensus(二)

目录 一、深入理解RSNSAC 二、RANSAC的缺点 三、PCL中常用的Sample Consensus 算法 四、参考资料 一、深入理解RSNSAC RANSAC是“RANdom SAmple Consensus”(随机抽样共识或采样一致性)的缩写,它是一种迭代方法,用于从包含异常值的一组数据中估计数学模型的参数。该算法由Fischler和Bolles于1981年发布。

如何用 Google Chrome 浏览器浏览经过 XSLT 渲染的XML 文件

对于经过 XSLT 渲染的XML 文件,本来,可以直接用 IE (Internet Explorer) 打开,就能看到渲染之后的样子,很方便。但是后来,微软把 IE 换成了 Microsoft Edge,按理说这是比 IE 更先进的浏览器,可是偏偏就不能直接打开经过 XSLT 渲染的XML 文件。为了这个问题,昨天真是把我折腾坏了,折腾了好几个办法,都不能像过去那样非常方便地浏览经过 XSLT 渲

Direct3D Tutorial Win32 Sample 详解 - 7

实现效果: 在cube上实现纹理映射 process: 将纹理坐标附加到顶点信息中; 使用工具将JPG等图片转化为DDS格式; 使用DDSTextureLoader module加载DDS,得到ID3D11ShaderResourceView。 填充D3D11_SAMPLER_DESC来创建ID3D11SamplerState 着色器代码如下: Texture2D txDiffuse : r

Direct3D Tutorial Win32 Sample 详解 - 6

实现效果 在tutorial 5的基础之上实现光照 不同光源及其属性 平行光 属性:方向,平行光不会随距离衰减 struct DirectionalLight{DirectionalLight() { memset(this, 0, sizeof(DirectionalLight)); }DirectX::XMFLOAT4 Ambient;DirectX::XMFLOAT4 Diffu

Direct3D Tutorial Win32 Sample 详解 - 5

实现效果: 一个cube自转,另一个cube自转同时,绕中心轴公转 要点 Transform 平移之后,坐标原点就不在物体的中心了。平移之后一定方向上的旋转就是公转。 两个立方体的transform过程如下: // 1st Cube: Rotate around the origin// 绕Y轴旋转即可g_World1 = XMMatrixRotationY( t );// 2n

android-percent-support-lib-sample

https://github.com/JulienGenoud/android-percent-support-lib-sample

linux mtd分区应用操作sample之某分区擦除

什么是擦除? 把flash相关的区域数据bit置为1的过程 #include <mtd/mtd-user.h>#include <mtd/mtd-abi.h>struct erase_info_user {__u32 start; // 起点 __u32 length; //长度 块大小对齐 不然报参数失败 };struct erase_info_user64 {