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>
Update: Two phase transformation with
node-set()extension function.This stylesheet:
Output:
Without extensions, this stylesheet: