Altova Mailing List Archives

Re: [xsl] xpath dynamic selection

From: Jeni Tennison <jeni@---------------->
Date: 7/11/2004 11:10:00 AM
Hi Wim,

I found it really quite difficult to follow your question. It would
help if you could show an small sample of your input XML and the
output that you'd like to generate from it, plus all the relevant
code. I'll try to answer your questions, though:

> When I look at all the examples every selection like
> select="child::item[@value>3]" has a constant value to test against ("3" in
> this case).
> Can't this be done with a variable? eg: 
> select="child::item[@value>$basevalue]"

Yes, it can.

> It try to do this by calling the alts in item with:
>   	<xsl:apply-templates match="alt">
> 	  <xsl:with-param name="step" select="$step"/>
> 	</xsl:apply-templates>
> with the $step number of the item
> and in alternative:
>     <xsl:param name="start">
> 	<xsl:value-of select="ancestor::*/*/alt[@number=$anumber]"/>
>     </xsl:param>    
> with $anumber the number of the alternative.
> But it returns nothing.

You haven't shown us how the $anumber parameter gets assigned its
value. Perhaps it's not getting set to the number that you think it's
getting set to?

> If I remove the "[@number=$anumber]" part it always returns 1, so I
> guess it returns the first match.

You're right that <xsl:value-of> always returns the value of the first
node that you select. Usually, when setting a variable or parameter,
it's a good idea to use the select attribute so that it holds all the
nodes that you select, as in:

  <xsl:param name="start"
    select="ancestor::*/*/alt[@number=$anumber]" />

I'm not sure that the path you're using is the one you want here; from
the sketch of the tree that you gave (though you described it as the
output rather than the input), perhaps it should be:

  <xsl:param name="start"
    select="../../alt[@number=$anumber]" />

If the <alternative> element is the current element, and you want the
<alt> element whose number attribute has the same value as the number
attribute on the current <alternative> element, then you could use:

  <xsl:param name="start"
    select="../../alt[@number=current()/@number]" />


> I also don't understand how I can get the @step value from the alt.
> adding /attribute::step after the */*/alt doesn't seem to work.

Without seeing your input XML and your XSLT code, it's impossible to
tell why this doesn't work.



Jeni Tennison


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 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.