[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Want to print elements/attrib specified by an XPath th

Subject: 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)
 Want to print elements/attrib specified by an XPath th
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.