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>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--