Reputation: 55
How do you wrap the "when" and "otherwise" results in a tag?
In my example below I tried adding a the div but it ends up wrapping each result.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" />
<xsl:include href="vcardbook.xsl" />
<xsl:template name="entriesLoopBook">
<div id="team-posts">
<xsl:for-each select="entries/entry ">
<div>
<xsl:choose>
<xsl:when test="$fid != 887">
<div class="physical">
<xsl:call-template name="vcardbook" />
</div>
</xsl:when>
<xsl:otherwise>
<div class="service">
<xsl:call-template name="vcardbook" />
</div>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:for-each>
</div>
<div style="clear:both;" />
</xsl:template>
</xsl:stylesheet>
Result from code above:
<div>
<div class="physical"><div class="567"></div></div>
<div class="physical"><div class="457"></div></div>
<div class="physical"><div class="342"></div></div>
<div class="service"><div class="887"></div></div>
<div class="service"><div class="887"></div></div>
</div>
How I would like it to look:
<div>
<div class="physical">
<div class="567"></div>
<div class="457"></div>
<div class="342"></div>
</div>
<div class="service">
<div class="887"></div>
<div class="887"></div>
</div>
</div>
Thank you for your help.
Upvotes: 1
Views: 1043
Reputation: 12075
As I rule I wouldn't recommend using for-each
, but to make as few changes to your code as possible, try this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" />
<xsl:include href="vcardbook.xsl" />
<xsl:template name="entriesLoopBook">
<div id="team-posts">
<div>
<div class="physical">
<xsl:for-each select="entries/entry[<wherever you get $fid from> != 887">
<xsl:call-template name="vcardbook"/>
</xsl:for-each>
</div>
<div class="service">
<xsl:for-each select="entries/entry[<wherever you get $fid from> = 887">
<xsl:call-template name="vcardbook"/>
</xsl:for-each>
</div>
</dv>
</div>
<div style="clear:both;" />
</xsl:template>
</xsl:stylesheet>
Upvotes: 1