0

i have an xml:

<newsletter country="nl">
<shop id="1">
<primaryOffer type="hunt">

Now i have an xslt:

<xsl:for-each select="//shop[@id='1']">
< do A>
</xsl:for-each>

now i am looking for an if statement, inside the xsl for each statement, which says: if primaryOffer type="hunt" do A, else do B

How do i do this?

I tried

<xsl:for-each select="//shop[@id='1']">
<xsl:if select="//primaryOffer[@type='hunt']">A</xsl:if>
B
</xsl:for-each>

Here is the xml: http://frisokc111.111.axc.nl/feed/nl.xml

Thanks!

Kemp
  • 21
  • 6
  • 2
    Kemp, You need to learn about the `` instruction. Actually, one doesn't need XSLT conditionals -- read and learn about the `` directive – Dimitre Novatchev Nov 27 '15 at 21:48
  • 1
    While following Dimitre's advice, you might benefit from these two SO questions: (1) [How to implement if-else statement in XSLT?](http://stackoverflow.com/q/13622338/290085) and (2) [differences between for-each and templates in xsl?](http://stackoverflow.com/q/4460232/290085) – kjhughes Nov 28 '15 at 02:45

1 Answers1

1

Got it, thanks

<xsl:choose>
   <xsl:when test="../primaryOffer[@type = 'hunt']">
      do a
   </xsl:when>
   <xsl:otherwise>
      do b
   </xsl:otherwise>
</xsl:choose>
Kemp
  • 21
  • 6