RE: Query use case: dynamically subselecting a sequence of named elements

> Suppose the element Stuff were defined as
> 
>    <!ELEMENT Stuff (Thing1, Thing2, ...., Thing99)>
> 
> If $aStuff identified a Stuff element node
> and $parts contained the sequence ('Thing24', 'Thing27', 'Thing82')
> 
> one would be sorely tempted to write  $aStuff/$parts
> to get the corresponding sub-elements of the Stuff node
> 
> That wouldn't work, but how easy would it be write the 
> necessary expression (preferably in XPath alone) given 
> $aStuff and $parts?

This kind of expression is very common in XSLT. The answer is:

  $aStuff/*[name()=$parts]

Michael Kay

Received on Thursday, 5 June 2003 05:00:25 UTC