xslt - ancestor-or-self wont select self -


there should simple solution cant work.

this code:

<xsl:value-of select="$currentpage/ancestor-or-self::* [@isdoc , backgroundimage != '' , string(umbraconavihide) != '1']/backgroundimage"/> 

what want if node has background image attached property backgroundimage, use image. if not have background image, check parent node background image , use that.

what happends me checks parents background image, if node has background image.

any suggestions on how resolve this?

update

<site id="1000" ...>     <backgroundimage>/media/image.jpg</backgroundimage>     <textpage id="1001" ...>         <backgroundimage>/media/image2.jpg</backgroundimage>     </textpage>     <textpage id="1002" ...>         <backgroundimage />     </textpage> </site> 

if i'm on <textpage id="1002"> backgroundimage null image.jpg <site id="1000">.

if i'm on <textpage id="1001"> backgroundimage not null, image2.jpg.

numeric predicates applied xpath address processed in proximity order, while resulting nodes addressed handed xslt processor in document order.

in xslt 1.0, <xsl:value-of> returns first of nodes returned, first of nodes in document order, if addressing of ancestors or self given properties, farthest one, not closest one. in xslt 2.0 of them.

since predicates applied in proximity order, use:

<xsl:value-of select="$currentpage/ancestor-or-self::*[...whatever...][1]"/> 

... closest of properties indicated "whatever" predicate.

the reason [last()] works in frank's solution parentheses return enclosed nodes in document order, closest 1 of last.

but semantics perspective, think reads better address first in proximity order.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -