Search

Hi,

I know how to do the image thing when I am using apply-templates, but how do I do it when I want to display a list of tags.

Here is my XML:

 <tags>
       <item handle="applications">Applications</item>
       <item handle="web-editing">Web Editing</item>
 </tags>

My XSLT:

 <xsl:template match="tags">
      <li><xsl:value-of select="item"/></li>
 </xsl:template>

and

 <ul><xsl:apply-templates select="tags"/></ul>

At the moment it is just displaying the one tag item.

Try:

<ul><xsl:apply-templates select="tags/item" /></ul>

and

<xsl:template match="item">
    <li><xsl:value-of select="." /></li>
</xsl:template>

Well that removes the <li> element.

Try match="tags/item" instead.

Well then that now spits out all the content that matches with tags/item, so I have the tags, the article itself, and so on.

If you have more elements that can be matched with tags/item try to be more specific in matching and selecting them (e.g. match="data/navigation/tags/item").

<xsl:template match="tags/item">
    <li><xsl:value-of select="."/></li>
</xsl:template>

<ul><xsl:apply-templates select="tags/item" /></ul>

Should work otherwise.

or...

 <xsl:template match="tags/item">
     <li><xsl:value-of select="."/></li>
 </xsl:template>

What I meant... changed my code above. Thanks.

No worries. Thanks for the help. Appreciate it.

you can also do this Nick:

<xsl:template match="tags">
    <xsl:for-each select="item" />
        <li><xsl:value-of select="."/></li>
    </xsl:for-each>
</xsl:template>

<ul><xsl:apply-templates select="tags" /></ul>

But I think what you have now is probably better.

remember, though, if you have html in what you want to output, use

<xsl:copy-of select="* | text()" />

I think that should copy the html (*) and the text (text()).

never used that last bit of code before.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details