Here's what I've got.
My data: data.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="myxslt2.xslt"?>
<data>
<foo>
<innerfoo1>inner-foo-1-text</innerfoo1>
<innerfoo2>inner-foo-2-text</innerfoo2>
</foo>
<bar>Hello World</bar>
<foobar>This is a test</foobar>
</data>
My metadata - this is tell the xslt which of the data nodes are to be displayed.
metadata.xml
<Metadata>
<Data>
<Detail>foobar</Detail>
<Detail>bar</Detail>
<Detail>foo/innerfoo1</Detail>
</Data>
</Metadata>
We want to display everything except innerfoo2.
My xslt: myxslt.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" version="1.0">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" indent="yes"/>
<xsl:variable name="main" select="/data"/>
<xsl:template name="myTemplate">
<xsl:param name="myparam"/>
<xsl:param name="node"/>
Node: <xsl:value-of select="$node"/><br/>
Inner:<xsl:value-of select="msxsl:node-set($myparam)/data/*[local-name() = $node][1]"/>
</xsl:template>
<xsl:template match="/data">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
HTML STARTS
<br/>
<xsl:variable name="data" select="."/>
Outer1:<xsl:value-of select="$data"/>
<br/>
Outer2:<xsl:value-of select="$data/foobar"/>
<br/>
<xsl:variable name="defaultMetadata" select="document('metadata.xml')"/>
<xsl:for-each select="msxsl:node-set($defaultMetadata)/Metadata/Data/Detail">
<br/>----<br/>
<xsl:call-template name="myTemplate">
<xsl:with-param name="node">
<xsl:value-of select="."></xsl:value-of>
</xsl:with-param>
<xsl:with-param name="myparam">
<xsl:copy-of select="$data"/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</html>
</xsl:template>
</xsl:stylesheet>
(pastebin for better readability - http://pastebin.com/Uw7bFYWM )
Output:
HTML STARTS
Outer1: inner-foo-1-text inner-foo-2-text Hello World This is a test
Outer2:This is a test
----
Node: foobar
Inner:This is a test
----
Node: bar
Inner:Hello World
----
Node: foo/innerfoo1
Inner:
So what I'm doing is looping through each detail element of the metadata, and calling the template passing in the data, the name of of the node to be displayed.
The template then resolves that node and displays it.
So you can see here that it resolves single level elements fine, but I can't use that local-name() = $node
comparison when it's more than one element deep.
What I'd like to do is something like:
Inner:<xsl:value-of select="msxsl:node-set($myparam)/data/$node"/>
But this doesn't work.
How can achieve this?