xsl-list
[Top] [All Lists]

[xsl] processing nodes by value precedence

2016-02-02 14:57:52
Lets say I’m processing products that can have multiple types of a certain node 
distinguished by value, of which I want only one in my result, and I have a 
precedence order by type of those nodes that shoudl determine which one I get.  
So, if the child of product I’m interested in is price currency and my product 
had

<product>
….

<price>
<amount>25.00</amount>
<currency>FR</currency>
</price>

<price>
<amount>20.00</amount>
<currency>US</currency>
</price>

<price>
<amount>30.00</amount>
<currency>CA</currency>
</price>

</product>

And my preference is to take the only one price in the order 1., US, 2. CA, 
3.FR.

In context product, if I say

<xsl:apply-templates 
select=“(price[currency=‘US’],price[currency=‘CA’],price[currency=‘FR’])[1]”/>

I get the FR price because it’s first in doc order, but my expression was meant 
to say process nodes in this sequence order, taking the first one, in the 
sequence, not in the doc order of the input tree.  

I thought the above instruction would be a short cut to achieving this, but it 
doesn’t work. Is there a concise way to express  the kind of precedence I want?

Thanks.



<Prev in Thread] Current Thread [Next in Thread>