基于计数的迭代或 XSL 中的复制。我该怎么做?
我正在尝试从 XML 数据创建一个库存列表(制表符分隔的文本,用于输出)。问题是,我需要获取我创建的行,并根据 XML 中找到的数字多次列出它(迭代???)。因此,从下面的 XML 中:
<?xml version="1.0" encoding="UTF-8"?>
<library>
<aisle label="AA">
<row>bb</row>
<shelf>a</shelf>
<books>4</books>
</aisle>
<aisle label="BB">
<row>cc</row>
<shelf>d</shelf>
<books>3</books>
</aisle>
</library>
我需要获取“books”中找到的值,然后复制文本行一定次数。结果如下所示:
Aisle Row Shelf Titles
AA bb a
AA bb a
AA bb a
AA bb a
BB cc d
BB cc d
BB cc d
这样盘点员就可以写下每个货架上找到的标题。我有 XSL 的基本结构,但我不确定如何执行“迭代”部分。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="tab" select="'	'"/>
<xsl:variable name="newline" select="' '"/>
<xsl:template match="/">
<!-- Start Spreadsheet header -->
<xsl:text>Aisle</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Row</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Shelf</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Titles</xsl:text>
<xsl:value-of select="$newline"/>
<!-- End spreadsheet header -->
<!-- Start entering values from XML -->
<xsl:for-each select="library/aisle">
<xsl:value-of select="@label"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="row"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="shelf"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$newline"/>
</xsl:for-each>
<!-- End of values from XML -->
<!-- Iteration of the above needed, based on count value in "books" -->
</xsl:template>
</xsl:stylesheet>
任何帮助将不胜感激。对于初学者来说,“迭代”是正确的术语吗?
谢谢!
I'm trying to create an inventory list (tab-delimited text, for the output) from XML data. The catch is, I need to take the line that I created, and list it multiple times (iterate ???), based on a number found in the XML. So, from the XML below:
<?xml version="1.0" encoding="UTF-8"?>
<library>
<aisle label="AA">
<row>bb</row>
<shelf>a</shelf>
<books>4</books>
</aisle>
<aisle label="BB">
<row>cc</row>
<shelf>d</shelf>
<books>3</books>
</aisle>
</library>
I need to take the value found in "books", and then copy the text line that number of times. The result looking like this:
Aisle Row Shelf Titles
AA bb a
AA bb a
AA bb a
AA bb a
BB cc d
BB cc d
BB cc d
So that the inventory taker, can then write in the titles found on each shelf. I have the basic structure of my XSL, but I'm not sure how to do the "iteration" portion.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="tab" select="' '"/>
<xsl:variable name="newline" select="'
'"/>
<xsl:template match="/">
<!-- Start Spreadsheet header -->
<xsl:text>Aisle</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Row</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Shelf</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Titles</xsl:text>
<xsl:value-of select="$newline"/>
<!-- End spreadsheet header -->
<!-- Start entering values from XML -->
<xsl:for-each select="library/aisle">
<xsl:value-of select="@label"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="row"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="shelf"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$newline"/>
</xsl:for-each>
<!-- End of values from XML -->
<!-- Iteration of the above needed, based on count value in "books" -->
</xsl:template>
</xsl:stylesheet>
Any help would be greatly appreciated. For starters, is "iteration" the right term to be using for this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有一个更简单的 XSLT 2.0 非递归解决方案:
And an even simpler XSLT 2.0 non-recursive solution:
这是一个简单的递归 XSLT 1.0 解决方案:
当此转换应用于提供的 XML 文档时:
生成所需的正确结果:
Here is a simple, recursive XSLT 1.0 solution:
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
写它0
我认为它会起作用
write it
<xsl:param name="pNumRows">0</xsl:param>
i think it will work