如何使用xsl样式表管理xml中的重复标签
大家好,我在这里面临一个小问题...... 如果假设我收到了 xml 文件格式,其中块标签下将存在一些块,某些块标签将不会重复,并且在某些块中标签将重复 前任: *
<block3>
<tag>
<name>113</name>
<value>FINANCIAL</value>
</tag>
</block3>
<block4>
<tag>
<name>32A</name>
<value>051028EUR9000,71</value>
</tag>
<tag>
<name>32A</name>
<value>051028EUR7000,71</value>
</tag>
<tag>
<name>33B</name>
<value>EUR9000,71</value>
</tag>
<tag>
<name>33B</name>
<value>EUR7000,71</value>
</tag>
<tag>
<name>71A</name>
<value>OUR</value>
</tag>
</block4>
<xsl:for-each select ="block3/tag[name = '113']">
<xsl:value-of select="value"/>
</xsl:for-each>,
<xsl:for-each select ="block4/tag[name = '32A']">
<xsl:value-of select="(translate(substring(value,10),',','.'))"/>,<xsl:text/>
</xsl:for-each>
<xsl:for-each select ="block4/tag[name = '33B']">
<xsl:value-of select="(translate(substring(value,1),',','.'))"/>,<xsl:text/>
</xsl:for-each>
*
我已经准备了如下所示的 xsl 样式表
输出:
如果没有标签重复性意味着
FINANCIAL, 9000.71,EUR9000.71
但这里 xml 标签在块内重复,所以我希望得到像
FINANCIAL, 9000.71,EUR9000 这样的结果。 71
金融,7000.71,7000.71 欧元
hi every body i have a facing a little problem here...
if suppose i have receiving a file format of xml in that some block will be there under the blocks tags will be coming for some blocks tags will not be repeated and in some blocks tags will be repeated
ex:
*
<block3>
<tag>
<name>113</name>
<value>FINANCIAL</value>
</tag>
</block3>
<block4>
<tag>
<name>32A</name>
<value>051028EUR9000,71</value>
</tag>
<tag>
<name>32A</name>
<value>051028EUR7000,71</value>
</tag>
<tag>
<name>33B</name>
<value>EUR9000,71</value>
</tag>
<tag>
<name>33B</name>
<value>EUR7000,71</value>
</tag>
<tag>
<name>71A</name>
<value>OUR</value>
</tag>
</block4>
<xsl:for-each select ="block3/tag[name = '113']">
<xsl:value-of select="value"/>
</xsl:for-each>,
<xsl:for-each select ="block4/tag[name = '32A']">
<xsl:value-of select="(translate(substring(value,10),',','.'))"/>,<xsl:text/>
</xsl:for-each>
<xsl:for-each select ="block4/tag[name = '33B']">
<xsl:value-of select="(translate(substring(value,1),',','.'))"/>,<xsl:text/>
</xsl:for-each>
*
i have prepared xsl style sheet bellow like this
Output :
if no tags repeatability means
FINANCIAL, 9000.71,EUR9000.71
but here xml tags are repeating in inside the block so i would like to expecting the result like
FINANCIAL, 9000.71,EUR9000.71
FINANCIAL, 7000.71,EUR7000.71
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您正在寻找一种从所有
标签输出相同数据的方法?您可以更改 XML 结构吗?如果不是 block3 和 block4,而是多个标签,将会有所帮助。然后你可以这样做:
这个模板将匹配所有
标签。然后,您只需在块/标签上应用模板即可。此行将对作为块标记子级的每个标记执行该过程。
但是,如果您无法更改 XML 的结构,只需保留模板并
为每个 blockN 执行:etc。
在我看来(根据我所学的),使用 apply-template(尽管作为初学者比 for-each 更难理解)比在 XSL 中使用循环要好得多,因为它是基于模板的语言。
这有帮助吗?你的问题问得不是很清楚。
if I understand you correctly, you are looking for a way to output the same data from all
<block>
tags?Are you able to change the XML structure? It would help if it wasn't block3 and block4, but just multiple tags. Then you could do something like this:
This template will match all
<tag>
tags. Then you simply apply templates over the blocks/tags.<xsl:apply-templates select="block/tag"/>
This line will carry out the process on every tag that is a child of a block tag.
But if you can't change the structure of the XML simply keep the template and do:
etc for each blockN.
In my opinion (from what I have been taught) using apply-templates (although more difficult to understand as a beginner than for-each) is much better than using loops in XSL as it is a template based language.
Does this help? Your question wasn't very clear.