I want to add an attribute element to node if and only if there is a data source for this attribute.
In other words, I do not want to end with empty attributes if the source does not match my rule.
<tok id="t1" fooID=""/>
<tok id="t1" />
<tok id="t1" fooID="bar"/>
Moreover, I would like to check if the source has more than 1 node that matches my current attribute, and if so, add another attribute foowith "source2". Here is what I am using now:<xsl:template match="tokens/token">
<tok id="{@ID}"
ctag="{/root/myStuff/fooSources[1and2 how?]/fooSource[@fooID=current()/@ID]}"
>
</tok>
The source XML looks like this:
<root>
<myStuff>
<tokens>
<token ID="bar"/>
<token ID="anotherBar"/>
<token ID="noFoo"/>
</tokens>
<fooSources>
<fooSource fooID="bar"> kitten </fooSource>
<fooSource fooID="anotherBar"> shovel </fooSource>
</fooSources>
<fooSources>
<fooSource fooID="bar"> kitty </fooSource>
<fooSource fooID="notAnotherBar"> fridge </fooSource>
</fooSources>
</myStuff>
</root>
The desired result will be as follows:
<tok id="bar" fooID="kitten" fooID_2="kitty"/>
<tok id="anotherBar" fooID="shovel"/>
<tok id="noFoo" />
Thanks in advance for your help!
PS: I would like to do this in xpath 1.0
source
share