Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Dynamic attribute selection

From: "Alex Cole" <a.cole@--------------->
To:
Date: 9/5/2008 1:20:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent