I mean to add an attribute element to a node if and only if the source for that attribute's data exists.
In other words, I don't want to end up with empty attributes in case the source isn't matched by my rule.
<tok id="t1" fooID=""/> //not accepted
<tok id="t1" /> //instead of ^
<tok id="t1" fooID="bar"/> //accepted
Moreover, I would like to test if the source has more than 1 node corresponding to my current attribute, and if so, add another
foo attribute with "source2". Here's what I'm currently using:
<xsl:template match="tokens/token">
<tok id="{@ID}"
ctag="{/root/myStuff/fooSources[1and2 how?]/fooSource[@fooID=current()/@ID]}"
>
</tok>
The source XML is 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 would be this:
<tok id="bar" fooID="kitten" fooID_2="kitty"/>
<tok id="anotherBar" fooID="shovel"/>
<tok id="noFoo" />
Thanks in advance for any help!
PS: I'd like to do this in xpath 1.0