xsl-list
[Top] [All Lists]

Re: [xsl] processing nodes by value precedence

2016-02-03 08:50:37

On Feb 2, 2016, at 4:09 PM, David Carlisle 
d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com<mailto:d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com>
 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
 wrote:



On 2 February 2016 at 20:57, Matthew Stoeffler 
matthew(_dot_)stoeffler(_at_)ithaka(_dot_)org<mailto:matthew(_dot_)stoeffler(_at_)ithaka(_dot_)org>
 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>wrote:
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<http://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.

No you should get the US one. if you execute

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

 <xsl:template match="product">
  <xsl:copy-of 
select="(price[currency='US'],price[currency='CA'],price[currency='FR'])[1]"/>
 </xsl:template>
</xsl:stylesheet>


on the xml you posted then you get

<price>

<amount>20.00</amount>

<currency>US</currency>

</price>

If I use xsl:copy-of I DO  get the US price, but I’m using xsl:apply-templates, 
and when I do that I get doc order.  How do I get past that?



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