提问人:SpaceStrip 提问时间:11/2/2023 最后编辑:TylerHSpaceStrip 更新时间:11/3/2023 访问量:51
使用 XSL 样式表打开 XML 派生数据时创建的不需要的行
Unwanted Rows Created When Opening XML Derived Data Using XSL Stylesheet
问:
我们使用 XSL 样式表从 RestAPI 命令中获得数据,该样式表以格式良好的方式填充浏览器。在浏览器情况下,“描述”字段/列占用一 (1) 个块/单元格,无论存在多少行分隔符、段落元素或列表。
当将浏览器 XML 导出到具有旧 XLS 扩展名的文件并提供相同的 XSL 样式表(为简单起见,在同一文件夹中)时,创建的 Excel 工作表(带表格)的行为与本地样式表的预期相同,但只要存在换行符、段落元素或列表,就会在“说明”列中生成额外的行(为简单起见,未提及其他可能性)。有趣的是,表中存在额外行的所有其他单元格都会自动合并。此外,任何具有多行数据的列都可能发生这种情况。
在创建一个 Excel 表格时,我们可以对所有数据(带有关联的“描述”)进行排序,我们现在遇到了一个不可能的问题,因为只有描述的第一个块(在中断元素之前)与排序的行一起携带,而额外行中的其余数据则被孤立为不可排序。
显然,我们正在寻找一种解决方案,在Excel中打开时,所有多行“描述”数据都保留在单个单元格中。我提供了 Excel 97“Multiline_Excel_Issue.xls”XML 数据和“TableXMLstylesheet.xsl”样式表的完整代码,它们需要位于同一文件夹中。打开 XLS 文件时,它会要求提供样式表并抱怨一些事情,并在网格线关闭的情况下以保护模式打开。这可以在信任设置中克服。
我怀疑对行<xsl:value-of disable-output-escaping=“yes” select=“进行了一些修改。XSL 样式表末尾的 /> 将是将所有多行“描述”数据组合在一起的关键,但欢迎所有想法。(顺便说一句,每个人都应该了解,如果多行文本用引号括起来并粘贴到 Excel 单元格中,它的行为和停留在单个单元格中)。
这是 Excel 工作表的样子,其中生成了额外的不需要的行。
如果样式表是固定的(没有生成额外的不需要的行),这就是 Excel 工作表的所需输出的样子。
对于 Excel 97 文件的 RestAPI XML 数据,请复制下面的块并另存为“Multiline_Excel_Issue.xls”
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="TableXMLstylesheet.xsl"?>
<Assets>
<Asset id="Single:01">
<Attribute name="Description">This is a statement with a single line "as in single" line.&nbsp; At this time I have no plans to change this line.<br></Attribute>
<Attribute name="Name">Single line has no issues</Attribute>
</Asset>
<Asset id="Multi:01">
<Attribute name="Description">This description has multiple lines separated by these BR line break objects. I want all the rows generated in Excel to go away/gone never to be seen. This does not show up in the browser. How can we fix the xsl stylesheet??.<br><br>Thank you for helping me understand the issue.&nbsp; It will be a great accomplishement to fix this problem.<br></Attribute>
<Attribute name="Name">Multiline HTML with line break elements</Attribute>
</Asset>
<Asset id="Empty:01">
<Attribute name="Description" />
<Attribute name="Name">This has no lines in Description</Attribute>
</Asset>
<Asset id="Multi:02">
<Attribute name="Description"><p>See https://someuselesswebsitedonotbotherclicking.com/dummy/index.php?title=Title_one/Status_one#Making_it_Work</p>
<p>&nbsp;</p>
<p>It would be great if this multiline example would show up in a single cell in Excel. Need to determine the cause/issue.</p></Attribute>
<Attribute name="Name">Multiline HTML with paragraph elements and URLs</Attribute>
</Asset>
<Asset id="Multi:03">
<Attribute name="Description"><p>This description has some multiline auto-generated numbering:</p>
<ol>
<li>This is the first line of the auto-numbered section/region.</li>
<li>And this is the second</li>
<li>And so on and so on and so on (will it stop?).</li>
</ol></Attribute>
<Attribute name="Name">Multiline HTML with auto line numbering elements</Attribute>
</Asset>
</Assets>
对于 XSL 样式表,复制下面的块并另存为“TableXMLstylesheet.xsl”
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Multiline Excel Issue</title>
<style type="text/css">
.columnheader {
background: rgba(200, 200, 200, .8);
border-style: solid;
border-color: blue;
}
.column {
background: rgba(230, 230, 230, 0);
vertical-align: top;
border-style: solid;
border-color: red;
}
</style>
</head>
<body>
<xsl:apply-templates select="Assets" />
<table>
<thead>
<tr>
<td class="columnheader">AssetID</td>
<xsl:for-each select="Assets/Asset[1]/child::*">
<td class="columnheader"><xsl:value-of select="@name"/></td>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="Assets/Asset" mode="Row" />
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Assets" />
<xsl:template match="Asset" mode="Row">
<tr>
<td class="column">
<a><xsl:value-of select="@id"/></a>
</td>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="Attribute">
<td class="column">
<xsl:value-of disable-output-escaping="yes" select="."/>
</td>
</xsl:template>
</xsl:stylesheet>
将所需结果 XLS 文件保存为 HTML 时生成的 HTML 片段。这是针对单元格 B3:
<td class="xl68" width="256" style="border-top:none;border-left:none;width:192pt">This
description has multiple lines separated by these BR line break objects. I
want all the rows generated in Excel to go away/gone never to be seen. This
does not show up in the browser. How can we fix the xsl stylesheet??.<br>
<br>
Thank you for helping me understand the issue. It will be a great
accomplishement to fix this problem.</td>
答: 暂无答案
评论
<br>