Search

Hey Guys, how I can add to content= a xsl:for-each ?

I try this :(

<meta name="keywords" content="<xsl:for-each select="data/meta-data/entry/keywords/item"><xsl:value-of select="@handle"/><xsl:text>&#044; </xsl:text></xsl:for-each> " />

thx

yes, but you have to use <xsl:attribute name="content">, like so:

<meta name="keywords">
   <xsl:attribute name="content">
      <xsl:for-each select="data/meta-data/entry/keywords/item">
         <xsl:value-of select="@handle"/><xsl:text>&#044; </xsl:text>
      </xsl:for-each>
   </xsl:attribute>
</meta>

hi phoque thank you ! can you tell me one more question ?

How I get the last @handle without the comma <xsl:text>&#044; </xsl:text>

something like this:

<meta name="keywords" content="handle1, handle2, handle1">

You have to compare position() to last():

<xsl:if test="position != last()">&#044; </xsl:if>

There is a typo. It should be:

<xsl:if test="position() != last()">&#044; </xsl:if>

Picking bugs on actual code is not enough, you have to pick code examples now hey? ;)

I didn't even pick up on the typo.

:-)

I often wish my programming skills would be half as good as my bug detection skills.

Michael, that shouldn't be a problem:

  • first: write ugly code.
  • second: proof-read it yourself.

You just have to use your skills on your own code ;)

That hurts.

Hah! classic.

Hey Guys,

thanks for helping ..but the last comma is still there ?

My Code:

<meta name="keywords"> <xsl:attribute name="content"> <xsl:for-each select="data/meta-data/entry/keywords/item"> <xsl:value-of select="@handle"/><xsl:text>&#044;</xsl:text> </xsl:for-each> </xsl:attribute> <xsl:if test="position != last()">&#044;</xsl:if> </meta>

My output:

<meta name="keywords" content="tag1,tag2,tag3,">

try <xsl:if test=". != last()">&#044;</xsl:if>

Change position to position() as Michael pointed out earlier.

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