xml - XSL:template & Combination of two match conditions to select outer node -
given following (part of a) xml file:
<span deltaxml:deltav2="a!=b"> <deltaxml:attributes deltaxml:deltav2="a!=b"> <dxa:class deltaxml:deltav2="a!=b"> <deltaxml:attributevalue deltaxml:deltav2="b">lof</deltaxml:attributevalue> </dxa:class> </deltaxml:attributes> text </span>
... want / need match <span>
nodes in <xsl:template match="..">
statement target spans with
- the span having deltaxml:deltav2 attribute 'a!=b' value ,
- the exact deltaxml:attributes/dxa:class/deltaxml:attributevalue child structure inner-most deltaxml:attributevalue node having deltaxml:deltav2 attribute set 'b' value , containing 'lof' value / text
basically need match exact condition shown above later select / use 'some text' part.. that's easy thing once matched <span>
node(s) in input xml.. far i've been scratching head , failed select node(s).
maybe fluent in more complex match statements , knows 1 correct 1 here. thanks!
you can create big predicate expression and
'ing , counting attributes. nodes not have matched directly because attributes without elements cannot exist. however, elements , attributes counted ensure there no more nor less elements/attributes in span
/element, respectively. text nodes not handled, merely existence of some text
checked.
so following complex expression match exactly element/attribute tree structure described:
<xsl:template match="span[ @deltaxml:deltav2='a!=b' , count(descendant::*)=3 , deltaxml:attributes/@deltaxml:deltav2 , count(deltaxml:attributes/@*)=1 , deltaxml:attributes/dxa:class/@deltaxml:deltav2 , count(deltaxml:attributes/dxa:class/@*)=1 , deltaxml:attributes/dxa:class/deltaxml:attributevalue/@deltaxml:deltav2='b' , count(deltaxml:attributes/dxa:class/deltaxml:attributevalue/@*)=1 , deltaxml:attributes/dxa:class/deltaxml:attributevalue/text()='lof' , normalize-space(text()[2])='some text']"> match! </xsl:template>
unfortunately comparing 2 resulting tree fragments in variables containing sub-trees not work because there no compare-op (see here).
Comments
Post a Comment