Search code examples
xsltsmarty

Possible to use variable in child node? (xslt/for-each)


in my ESP (email service provider) i have a list or customers with variables, and i have xslt which parsed the XML feed into a (dynamic) mail. Now, i want to personalise my mails, sending different content to different email subscribers.

I have a variable $profile.pos1_day_camp (can be numeric values) and i want to show them content based on this variable. The content differs with the child node. Its the @id of a shop.

so, show

{if $profile.pos1_day_camp == 1}
<xsl:for-each select="//shop[@id='1']/offer]">
**"show content of shop id 1"**
</xsl:for-each>
{/if}

{if $profile.pos1_day_camp == 17}
<xsl:for-each select="//shop[@id='17']/offer]">
**"show content of shop id 17"**
</xsl:for-each>
{/if}

etc. But this will become too much code, since there are many possible values, therefore i am looking to place the variable inside the for-each. Is that possible? If i do this, it shows nothing:

<xsl:for-each select="//shop[@id='{$profile.pos1_day_camp}']/offer">
**"show content of shop id xx"**
</xsl:for-each>

Thanks!


Solution

  • Got it, thanks

    <xsl:for-each select="shop">
    {if $profile.pos1_daily == <xsl:value-of select="@id" />}
            ....
    <xsl:for-each select="offer">
    </xsl:for-each>  
    {/if}
    </xsl:for-each>