tylik
tylik

Reputation: 1068

xslt apply 2 templates with different modes, on the same element while preserving order defined in xml

I have an xml file with items. I want to output the list of items depending on the view attribute and preserve the order of the elements. For this purpose I have to xsl:templates with different modes. The problem is that I can't preserve the same order as in xml. The xml is following:

   <item />
   <item view="new" />
   <item />
   <item view="new" />

the templates are:

<xsl:template match="item" mode="standart">
    <div class="standart_item"></div>
</xsl:template>

<xsl:template match ="item" mode="new">
    <div class="new_item"></div>
</xsl:template>

How can I apply different templates to preserve the order, the same as in xml?

<div class="standart_item"></div>
<div class="new_item"></div>
<div class="standart_item"></div>
<div class="new_item"></div>

Upvotes: 0

Views: 427

Answers (1)

Martin
Martin

Reputation: 1788

Using different modes doesn't seem to be the right tool for the result you're trying to achieve. I suggest to distinguish the templates by predicates:

<xsl:template match="item">
  <div class="standard_item"></div>
</xsl:template>

<xsl:template match="item[@view='new']">
  <div class="new_item"></div>
</xsl:template>

Upvotes: 1

Related Questions