XSL:for 循环中的标记化问题
我使用以下样式表在 Excel 工作簿中显示包含数据的表格。我无法获得所需的结果,而是显示的结果与下面给出的不同。
请提出建议?
使用的样式表:
<xsl:stylesheet>
<xsl:template match="/">
<xsl:variable name="test1" select="str:tokenize('1$,$2$,$3$,$4$,$5','$,$')" />
<xsl:variable name="test2" select="str:tokenize('a$,$b$,$c$,$d$,$e','$,$')" />
<xsl:for-each select="str:split('1a$,$2b$,$3c$,$4d$,$5e','$,$')>
<row>
<cell Index="1">
<xsl:value-of select="$test1[position()]" />
</cell>
<cell Index="2">
<xsl:value-of select="$test2[position()]" />
</cell>
</row>
</xsl:for-each>
</xsl:template>
预期结果:
1 a
2 b
3 c
4 d
5 e
结果显示为
a b
c d
e
看起来它正在显示最新的 tokenize 值。 如何获得受人尊重的价值观。
I am using the following stylesheet for displaying a table in the excel workbook with the data. I am not able to get the desired result instead it is displaying as differently as given below.
Suggestions Pls?
The stylesheet used:
<xsl:stylesheet>
<xsl:template match="/">
<xsl:variable name="test1" select="str:tokenize('1$,$2$,$3$,$4$,$5','$,
Expected Result:
1 a
2 b
3 c
4 d
5 e
Where as the result displayed as
a b
c d
e
It seems like the it is displaying the latest tokenize values.
How to get respected values.
)" />
<xsl:variable name="test2" select="str:tokenize('a$,$b$,$c$,$d$,$e','$,
Expected Result:
1 a
2 b
3 c
4 d
5 e
Where as the result displayed as
a b
c d
e
It seems like the it is displaying the latest tokenize values.
How to get respected values.
)" />
<xsl:for-each select="str:split('1a$,$2b$,$3c$,$4d$,$5e','$,
Expected Result:
1 a
2 b
3 c
4 d
5 e
Where as the result displayed as
a b
c d
e
It seems like the it is displaying the latest tokenize values.
How to get respected values.
)>
<row>
<cell Index="1">
<xsl:value-of select="$test1[position()]" />
</cell>
<cell Index="2">
<xsl:value-of select="$test2[position()]" />
</cell>
</row>
</xsl:for-each>
</xsl:template>
Expected Result:
1 a
2 b
3 c
4 d
5 e
Where as the result displayed as
a b
c d
e
It seems like the it is displaying the latest tokenize values.
How to get respected values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好问题,+1。
在我看来,而不是:
这必须是:
第二个观察结果完全相同
解释:
任何表达式都
等价于:
因为
position()
只能有值 >= 1 和[position()]< /code> 表示 布尔值
position()
,任何非负数的布尔值根据定义都是true()
。如果我们想在 XPath 1.0 中选择节点集 $var 中的第 $k 个节点,该节点是弱类型的并且不知道
$k
包含一个整数,我们有写:这是一个完整的、相应的 XSLT 2.0 解决方案:
当应用于任何 XML 文档(忽略)时,会产生所需的正确结果:
Good question, +1.
It seems to me that instead of:
this must be:
Exactly the same observation holds for the second
<xsl:value-of>
Explanation:
Any expression
is equivalent to:
because
position()
can only have values >= 1 and[position()]
means the boolean value ofposition()
, and the boolean value of any non-negative number by definition istrue()
.If we want to select the $k-th node in the node-set $var, in XPath 1.0, which is weakly-typed and it isn't known that
$k
holds an integer, we have to write:Here is a complete, corresponding XSLT 2.0 solution:
when applied on any XML document (ignored), the wanted, correct result is produced: