0

I have a product feed with around 500 products in it, I am using this to load into e-mails. I load this feed from a feed management tool into my XSLT and I want to choose only specific items that all have the value 'test1' in the field 'visibility' (would be around 35 items), but then I only want to load 3 items. So 500 products in total in the feed - 35 with the value 'test1' in the field 'visibility' and output would be only 3 (with additional sort of price low - high).

I was able to either choose the products with the specific field OR choose only 3 products. But never both rules in one.

I tried the following:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="items">
  <!-- start the items -->
 <xsl:call-template name="item" />
 </xsl:template>
 <xsl:template name="item">
    <xsl:for-each select="item">
      <xsl:sort select="price" order="ascending"/>
         <xsl:choose>
            <xsl:when test="visibility = 'test1'">
               <xsl:if test="(position() &lt;= 3)">

The output doesn't show any products though. Apart from each other, they do work. I also tried to first use the IF and then the choose / when rules, but that did not work either.

I did see that people were using rules in the for-each function, but I don't know how that works (I am not a developer, only an online marketing consultant).

For that I tried

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="items">
  <!-- start the items -->
 <xsl:call-template name="item" />
 </xsl:template>
 <xsl:template name="item">
    <xsl:for-each select="item and LogResults/Result[visibility='copernica']">
      <xsl:sort select="price" order="ascending"/>
<xsl:choose>
       <xsl:when test="position() &lt;= 4">

But that did not work either, I always get runtime errior or error element for each.

I hope someone can help me out!

Martje
  • 1
  • 1
    Should be an easy solution for that. But I would need the input data xml example for that. I can imagine that visibility is an attribute. To check attributes you need to put an '@' in front of it like: LogResults/Result[@visibility='copernica']. In that case the visibility attribute is on the node. Should look like .. in the cml data – Christian Mosz Jan 20 '20 at 08:48
  • 1
    How does your XML structure look exactly? If you want to process all `item` elements where the child element `visibility` has that `test1` value then use a predicate `item[visibility = 'test1']`. – Martin Honnen Jan 20 '20 at 08:50
  • @MartinHonnen thank you! that one worked out just perfect! Now it seems so logical, but for someone who never learned this, it's a bit tricky! Thank you for the quick response Christian and Martin! – Martje Jan 20 '20 at 09:01

0 Answers0