xslt-1.0 - 使用 XSLT 转换 XML 以构建表格
问题描述
我有如下内容的 XML 文件
<export>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">GD S408.810</field>
<field tableshort="AP" fieldno="40" value="0">12</field>
<field tableshort="C001" fieldno="4">GD S408.811241</field>
<field tableshort="C001" fieldno="4">13</field>
</row>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">GD S408.810</field>
<field tableshort="AP" fieldno="40" value="0">12</field>
<field tableshort="C001" fieldno="4">GD S408.81XXA</field>
<field tableshort="C001" fieldno="4">18</field>
</row>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">GD S408.810</field>
<field tableshort="AP" fieldno="40" value="0">12</field>
<field tableshort="C001" fieldno="4">GD S408.BFSSF</field>
<field tableshort="C001" fieldno="4">220</field>
</row>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">XX1</field>
<field tableshort="AP" fieldno="40" value="0">16</field>
<field tableshort="C001" fieldno="4">GD S408.811241</field>
<field tableshort="C001" fieldno="4">21</field>
</row>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">XX1</field>
<field tableshort="AP" fieldno="40" value="0">16</field>
<field tableshort="C001" fieldno="4">GD S408.81FSS</field>
<field tableshort="C001" fieldno="4">13</field>
</row>
<row>
<field tableshort="PR" fieldno="7006">2018/12/2180000101/O</field>
<field tableshort="PR" fieldno="7007">42</field>
<field tableshort="AP" fieldno="4">XX1</field>
<field tableshort="AP" fieldno="40" value="0">16</field>
<field tableshort="C001" fieldno="4">GD S408.811PKA</field>
<field tableshort="C001" fieldno="4">17</field>
</row>
我想使用 XSLT (1.0) 转换来转换这个内容并达到附加图片的效果,这是带有标记映射的 html 表
附加的 XML 只是示例。我们有超过 1000 行的 XML,所以我需要构建一个循环或几个循环来自动获取这些值。
这是我目前正在工作的代码:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" media-type="text/xml" />
<xsl:param name="ImageFolder">.</xsl:param>
<xsl:param name="Font">Verdana</xsl:param>
<xsl:param name="FontHeader">Cera Pro</xsl:param>
<xsl:param name="FontSize">8</xsl:param>
<xsl:param name="CellPadding">2.0</xsl:param>
<xsl:param name="CellSpacing">0.0</xsl:param>
<xsl:param name="HeaderBackgroundColor">#92bcde</xsl:param>
<xsl:param name="HeaderBorderColor">#92bcde</xsl:param>
<xsl:param name="HeaderBorderWidth">1.0</xsl:param>
<xsl:param name="AlternateCellBackgroundColor">#F0F0F0</xsl:param>
<xsl:param name="Leading">8</xsl:param>
<xsl:param name="Count"/>
<xsl:param name="Ext">.png</xsl:param>
<xsl:param name="PozCheck"/>
<xsl:param name="PozCheck5"/>
<xsl:param name="count" />
<xsl:template match="/" >
<xsl:variable name="NumberOfColumns"
select="count(export/fields/field)"/>
<itext pagesize="A4" orientation="portrait">
<xsl:for-each select="//row">
<xsl:variable name="Duplicate1">
<xsl:value-of select="field[@fieldno='141' and @tableshort='AP']" />
</xsl:variable>
<xsl:variable name="Duplicate2">
<xsl:value-of select="field[@fieldno='7007' and @tableshort='C001']" />
</xsl:variable>
<xsl:variable name="Loop1">
<xsl:value-of select="field[@fieldno='40' and @tableshort='AP']" />
</xsl:variable>
<xsl:variable name="LoopBreak2">
<xsl:value-of select="field[@fieldno='40' and @tableshort='AP']" />
</xsl:variable>
<xsl:variable name="LoopBreak1">
<xsl:value-of select="field[@fieldno='40' and @tableshort='AP']" />
</xsl:variable>
<xsl:value-of select="'_'"/>
<xsl:value-of select="field[@fieldno='40' and @tableshort='AP']" />
<xsl:for-each select="//row">
<xsl:variable name="Loop2">
<xsl:value-of select="field[@fieldno='40' and @tableshort='AP']" />
</xsl:variable>
<xsl:if test="$Loop1=$Loop2">
<xsl:value-of select="'_'"/>
<xsl:value-of select="field[@fieldno='4' and @tableshort='C001']" />
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</itext>
</xsl:template>
您能否建议如何实现这一目标?
解决方案
推荐阅读
- sql-server - 如果我进行事务日志备份并截断日志文件,我会丢失数据吗?
- java - Java 程序无法执行它写入 /tmp 的文件,没有这样的文件或目录
- flutter - 在按钮上单击导航到选项卡屏幕
- java - 将空字段反序列化为 null 而不是采用默认值
- android - Xamarin App Android 上的输入调度超时错误
- reactjs - 当我调用 DrawerOpen 时,抽屉不会打开到 initialRouteName
- bootstrap-4 - Bootstrap 4 - 具有固定边距的动态居中列数
- javascript - 上传 HTML 格式的图片并获取图片路径
- jmx - 每分钟将数据记录到 grafana
- android - 房间更新后将回收站视图滚动到新位置