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

Dynamic attribute selection

Subject: Dynamic attribute selection
From: "Alex Cole" <a.cole@xxxxxxxxxxxxxxx>
Date: Fri, 5 Sep 2008 14:19:50 +0100
 Dynamic attribute selection
Hello all

I am trying to create a template to select values from a node based on
whether or not that node contains a certain attribute, for example:

<p>
	<c x="" y="27" />
	<c z="" y="67" />
</p>

<xsl:value-of select="p/c[@x]/@y]" />

That will display 27 as expected and required, and this is exactly the
effect I want, however I am having trouble porting it to a template where
you can specify as a parameter the name of the attribute you want to ensure
is present.  The code I currently have looks something like:

<p>
	<c x="" y="27" />
	<c z="" y="67" />
</p>

<xsl:call-template name="MY_TEMPLATE"><xsl:with-param name="t" select="'x'"
/></xsl:call-template>

<xsl:template name="MY_TEMPLATE">
	<xsl:param name="t" />
	<xsl:value-of select="p/c[$t]/@y]" />
</xsl:template>

However that obviously doesn't work.  I've tried all sorts of methods
including using <xsl:key name="ATTR_NAME" match="@*" use="name()"/> to check
it, but it didn't like using that with the additional path parts.  Looping
though all c's to try test the existence of that using <xsl:if test="$t">,
but that just seems to evaluate the string, not the value of the attribute
represented by the string and I'm sure a few other methods I've lost track
of.  I've been trying to get this to work for quite a while now, I've found
a few useful things round and about, but nothing that works.

I am using the default javax 1.5 XSL library on eclipse 3.4

Any assistance in this matter would be greatly appreciated, I'm beginning to
lose hair over this one.

Thank you in advance

Alex Cole

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-2007 All Rights Reserved.