XSL:从多个 xml 文件中的子节点构建唯一的映射,然后将其显示在表格中
使用 XSL 从子节点构建唯一的映射,然后将其显示在表中
我想创建一个 xsl,它将以下 xml 文档作为输入
Source.xml
<root>
<children>
<child>
Source-A
</child>
<child>
Source-B
</child>
</children>
</root>
Source-A.xml
<child>
<Objects>
<Object>
<Key>Key-1234</Key>
</Object>
<Object>
<Key>Key-5678</Key>
</Object>
</Objects>
</child>
Source-B.xml
<child>
<Objects>
<Object>
<Key>Key-5678</Key>
</Object>
<Object>
<Key>Key-ABCD</Key>
</Object>
</Objects>
</child>
并创建一些 html 输出看起来像这样。
<table border=1>
<tr>
<td>
Key
</td>
<td>
Key-1234
</td>
<tr>
</tr>
<td colspan="2">
Source-A
</td>
</tr>
<tr>
<td>
Key
</td>
<td>
Key-5678
</td>
<tr>
</tr>
<td colspan="2">
Source-A
Source-B
</td>
</tr>
<tr>
<td>
Key
</td>
<td>
Key-ABCD
</td>
<tr>
</tr>
<td colspan="2">
Source-B
</td>
</tr>
</table>
这是我到目前为止所拥有的,但我不确定这是否可能,关于如何做到这一点有任何提示吗?或者我正在尝试做一些不可能的事情?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<!--<xsl:variable name="keyMap" />-->
<xsl:variable name="keyMap">
<xsl:for-each select="root/children/child">
<xsl:variable name="object" select="."/>
<!--<xsl:value-of select="$object"/>-->
<xsl:for-each select="document(concat(translate($object,' ',''),'.xml'))/child/Objects/Object">
<xsl:value-of select="Key"/>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$keyMap"/>
</html>
</xsl:template>
</xsl:stylesheet>
Use XSL to build a unique map from child nodes, then display it in a table
I would like to create a xsl that takes the following xml documents as input
Source.xml
<root>
<children>
<child>
Source-A
</child>
<child>
Source-B
</child>
</children>
</root>
Source-A.xml
<child>
<Objects>
<Object>
<Key>Key-1234</Key>
</Object>
<Object>
<Key>Key-5678</Key>
</Object>
</Objects>
</child>
Source-B.xml
<child>
<Objects>
<Object>
<Key>Key-5678</Key>
</Object>
<Object>
<Key>Key-ABCD</Key>
</Object>
</Objects>
</child>
and creates some html output that looks like this.
<table border=1>
<tr>
<td>
Key
</td>
<td>
Key-1234
</td>
<tr>
</tr>
<td colspan="2">
Source-A
</td>
</tr>
<tr>
<td>
Key
</td>
<td>
Key-5678
</td>
<tr>
</tr>
<td colspan="2">
Source-A
Source-B
</td>
</tr>
<tr>
<td>
Key
</td>
<td>
Key-ABCD
</td>
<tr>
</tr>
<td colspan="2">
Source-B
</td>
</tr>
</table>
Here is what I have so far, but I'm not sure it's even possible, any hints on how to do it? Or am I trying to do something thats not possible?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<!--<xsl:variable name="keyMap" />-->
<xsl:variable name="keyMap">
<xsl:for-each select="root/children/child">
<xsl:variable name="object" select="."/>
<!--<xsl:value-of select="$object"/>-->
<xsl:for-each select="document(concat(translate($object,'
',''),'.xml'))/child/Objects/Object">
<xsl:value-of select="Key"/>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$keyMap"/>
</html>
</xsl:template>
</xsl:stylesheet>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:使用
node-set()
扩展函数进行两阶段转换。此样式表:
输出:
没有扩展名,此样式表:
Update: Two phase transformation with
node-set()
extension function.This stylesheet:
Output:
Without extensions, this stylesheet: