[xsl] Want to print elements/attrib specified by an XPath that is passed as a param

Subject: [xsl] Want to print elements/attrib specified by an XPath that is passed as a param
From: John Christopher <john.christopher1100@xxxxxxxxx>
Date: Mon, 15 Jun 2009 20:04:48 -0700 (PDT)
My goal: I want an XSLT stylesheet that displays the contents
of any element or attribute whose name I pass to the stylesheet
as an XPath via a param.

The important thing is, the stylesheet should work with any
input XML, and should be able to print any matching elements
or attributes, depending on the XPath I pass as a param.  
The XPath cannot be hardcoded in the stylesheet.

For example, if I have the following XML file as input:

<rolodex>
	<entry id="S">
		<name>Smith, Dave</name>
		<phone>111-222-3333</phone>
	</entry>
	<entry id="W">
		<name>Wilson, Mary</name>
		<phone>222-333-4444</phone>
	</entry>
	<entry id="E">
		<name>Edwards, Paula</name>
		<phone>333-444-5555</phone>
	</entry>
</rolodex>

I want to pass the XPath "/rolodex/entry/name" as a param to
the stylesheet, and have the stylesheet print:

Smith, Dave
Wilson, Mary
Edwards, Paula

If I pass the XPath "/rolodex/entry/@id" as a param to the
stylesheet, the stylesheet should print:

S
W
E


So far, my stylesheet looks like this (see below).  What am
I doing wrong?  Thanks in advance for your help.


<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="text"/>
<xsl:param name="xpath"/>
<!-- ################################################## -->
<xsl:template match="/">
<!-- value of xpath is <xsl:value-of select="$xpath"/> -->
<xsl:apply-templates match="$xpath"/>
</xsl:template>
<!-- ################################################## -->
</xsl:stylesheet>

Current Thread