- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 XML 数据文件,其中包含许多图像路径,这些图像路径使用以下 XSL 样式显示在表格中
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="ArrayOfShoeprintDetails/ShoeprintDetails">
<table border="2" Width="50" cellspacing="0" cellpadding="5" style="font-family:arial">
<tr>
<th align="right">Reference</th>
<td>
<xsl:value-of select="Reference"/>
</td>
</tr>
<tr>
<th align="right">Images</th>
<td>
<xsl:for-each select="Images/ShoeImage">
<img width="100" height="auto">
<xsl:attribute name="src">
<xsl:value-of select="DecryptedFilename"/>
</xsl:attribute>
</img>
</xsl:for-each>
</td>
</tr>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如您所见,为 XML 文件中的每个根元素生成一个表,其中两行用于引用和图像。
图像设计为显示在第二行第二列的嵌套表格中。
问题是表格不断扩展以将图像保持在一行中(最多可能有 15 张图像。但是我希望图像“换行”以便最多显示 5 张图像,然后它在表格中开始一个新行,但我不知道如何完成。
我试过不使用嵌套表格,但这会以堆叠方式显示图像,一个堆叠在另一个之上,而不是并排显示。
这背后的基本原理是我想打印文档并且打印时一些图像被剪切掉。
编辑
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="ReportTemplate.xsl"?>
<ArrayOfShoeprintDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ShoeprintDetails>
<Reference>Item 1</Reference>
<Images>
<ShoeImage>
<DecryptedFilename>C:\79136</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79137</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79138</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79139</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79140</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79141</DecryptedFilename>
</ShoeImage>
<ShoeImage>
<DecryptedFilename>C:\79142</DecryptedFilename>
</ShoeImage>
<Images>
</ShoeprintDetails>
</ArrayOfShoeprintDetails>
最佳答案
如果您希望每行只有五张图片(并且不关心每张图片的大小),则可以采取的方法是从选择每行中最先出现的图片开始;即第 1、6、11(等)图像
<xsl:for-each select="Images/ShoeImage[position() mod 5 = 1]">
然后,对于每个这样的图像,您将获得构成该行的图像,就像这样
<xsl:for-each select=".|following-sibling::ShoeImage[position() < 5]" />
试试这个 XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="imagesPerRow" select="5" />
<xsl:template match="/">
<xsl:for-each select="ArrayOfShoeprintDetails/ShoeprintDetails">
<table border="2" Width="50" cellspacing="0" cellpadding="5" style="font-family:arial">
<tr>
<th align="right">Reference</th>
<td><xsl:value-of select="Reference"/></td>
</tr>
<xsl:for-each select="Images/ShoeImage[position() mod $imagesPerRow = 1]">
<tr>
<th align="right">Images</th>
<td>
<xsl:apply-templates select=".|following-sibling::ShoeImage[position() < $imagesPerRow]" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="ShoeImage">
<img width="100" height="auto" src="{DecryptedFilename}" />
</xsl:template>
</xsl:stylesheet>
请注意,我在这里参数化了“5”,并且我还切换到使用 xsl:apply-templates
只是为了减少缩进!
另请注意在创建 src
属性时使用属性值模板。花括号 { }
表示要计算的表达式,而不是按字面意义输出。
编辑:这更像是一个 HTML 问题,即 XSLT,但如果您只想显示一次“图像”标题单元格,请尝试以下操作:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:param name="imagesPerRow" select="5" />
<xsl:template match="/">
<xsl:for-each select="ArrayOfShoeprintDetails/ShoeprintDetails">
<table border="2" Width="50" cellspacing="0" cellpadding="5" style="font-family:arial">
<tr>
<th align="right">Reference</th>
<td><xsl:value-of select="Reference"/></td>
</tr>
<xsl:variable name="images" select="Images/ShoeImage" />
<xsl:for-each select="$images[position() mod $imagesPerRow = 1]">
<tr>
<xsl:if test="position() = 1">
<th align="right" rowspan="{ceiling(count($images) div 5)}">Images </th>
</xsl:if>
<td>
<xsl:apply-templates select=".|following-sibling::ShoeImage[position() < $imagesPerRow]" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="ShoeImage">
<img width="100" height="auto" src="{DecryptedFilename}" />
</xsl:template>
</xsl:stylesheet>
关于html - 在 XSL 中像 WPF WrapPanel 一样显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27567976/
我知道这可能看起来像一个愚蠢/新手问题,但我对 XSLT 还很陌生(尽管我开始接受它并了解它的功能)。 什么时候适合使用xsl:if,什么时候适合使用xsl:choose/xsl:when? 当我想要
在根据节点是否存在设置变量后,我尝试输出变量的文字字符串值。我认为条件检查逻辑是正确的。但它没有输出值... su
我目前正试图使用 XSL 将 XML 文档转换为 HTML。 XML 文档使用 namespace ,我对 XSL 并没有太多经验,更不用说 namespace 了。基本上我想做的就是抓取 s:t
你能否在嵌套的 xsl:when 中嵌套 xsl:if,例如:
我正在 W3Schools 上使用 XSLT 代码示例:https://www.w3schools.com/xml/xsl_client.asp 我有这部分代码在 IE 中使用基本的 xslt 处理.
我正在尝试从 XSLT 样式表动态生成 XSLT 文档。原则上这当然有效,但我没有让命名空间工作。我想让生成的 XSLT 元素以“xsl”前缀为前缀: 而不是 我玩过 xsl:element 的
我们客户的要求是提供带圆角的 PDF 表格。我只有 Apache FOP 处理器可供我使用,它不支持圆角属性。它也不支持 float ,因此无法向左和向右 float 圆形图像。 你对如何做到这一点有
我有一个关于 xsl 的问题。我有 1 个巨大的 xsl 文件(+4000 行 :p),我想将文件分成不同的部分。我使用 xsl 文件来映射 BizTalk 中的一些架构,如果我将它分成几部分,它的性
我的 FO 流程有问题,因为在一页上,标题显示在一页的末尾并在之后的页面上继续。如何向 title-element 添加属性,以便标题始终显示在同一页面上,这意味着:没有分页符。 谢谢! /丹尼 最佳
我想知道是否有人可以帮助我或指出正确的方向。我目前有从 XML 文件返回正确的元素有些麻烦。我只是尝试获取我拥有的大型 XML 文件的精简版本,以便输出另一个 XML 文件(不是很多教程都在使用的 H
我想动态创建具有动态名称的变量以供以后在我的转换中使用,但为此我需要动态生成 XSL,然后在同一脚本中运行它。 这只是我正在寻找的粗略伪代码示例。
我正在学习 XML 以及如何使用 XSL 文件。在 XSL 文件中,我发现了以下术语: xsl:template match="/" 这代表什么?我可以用什么代替 /?我可以编写 table 或任何其
是否可以将 xsl: 放到 XSL 样式表中的 XSL 标签? 例如,可以: 输入为: 编辑:样式表中包含 HTML 和 XML 节点。 谢谢,罗斯 最佳答案 实际上,您可以通过将 XSLT(“h
有什么办法不离开后第一 匹配但继续检查其他条件? 最佳答案 我相信这是一个不。正如规范所说: The content of the first, and only the first, xsl:whe
在构建 XSL 文档时,我遇到了以下问题。我想保留原文中的换行符,所以我设置了linefeed-treatment="preserve" .然而,这显然也意味着它保留了文本内容之外和实际 xml 元素
我有一个 XSL 样式表,我需要使用 xsl:function 添加一些自定义字符串操作。但是我在尝试找出在我的文档中放置该函数的位置时遇到了麻烦。 我的 XSL 简化看起来像这样,
我有以下 XML: Picture 1 Picture 2 Picture 3 虽然此 XSL 执行了预期的操作(输出第一张图片的属性):
我希望 column-count="2"只出现在页面的某些部分。 ]>
我正在为我的 XML 内容生成 xsl-fo 文档,然后将此内容传递给将生成 PDF 的第三方 DLL 之一。我需要以 45 度角显示测试。如何实现这一目标? 谢谢 最佳答案 我很确定您不能在纯 XS
在我的情况下,我必须在两个表格行之间提供高达 0.5cm 的空间。我怎样才能做到这一点。 代码:: 我用过了:
我是一名优秀的程序员,十分优秀!