4 users online. Create an account or sign in to join them.Users

Search

I’m making a portfolio, and each item is displayed in a list. I have the following XSL at the moment:

<li class="{../catagory/item}">

This outputs a category in the class name, which works perfect. However, I want to be able to select 2 or more categories, so the HTML output would be this:

<li class="category1 category2 category3">

My XML is this:

<category>
<item handle="category1">category1</item>
<item handle="category2">category2</item>
<item handle="category3">category3</item>
</category>

What would be the best way to achieve this? Thanks!

Try the <xsl:attribute /> element.

<li>
   <xsl:attribute name="class">
      <xsl:for-each select="category/item">
        <xsl:value-of select="." /><xsl:text> </xsl:text>
      </xsl:for-each>
   </xsl:attribute>
</li>

And to avoid the space after the last class :-)

<li>
    <xsl:attribute name="class">
        <xsl:for-each select="category/item">
            <xsl:value-of select="." />
            <xsl:if test="position() != last()">
                <xsl:text> </xsl:text>
            </xsl:if>
        </xsl:for-each>
    </xsl:attribute>
</li>

Brilliant! Cheers guys, works perfectly!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details