XSLT Syntax problem
This is an open discussion with 12 replies, filed under General.
Search
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>, </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>, </xsl:text>
something like this:
<meta name="keywords" content="handle1, handle2, handle1">
You have to compare position()
to last()
:
<xsl:if test="position != last()">, </xsl:if>
There is a typo. It should be:
<xsl:if test="position() != last()">, </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>,</xsl:text>
</xsl:for-each>
</xsl:attribute>
<xsl:if test="position != last()">,</xsl:if>
</meta>
My output:
<meta name="keywords" content="tag1,tag2,tag3,">
try <xsl:if test=". != last()">,</xsl:if>
Change position
to position()
as Michael pointed out earlier.
Create an account or sign in to comment.
Hey Guys, how I can add to
content=
axsl: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>, </xsl:text></xsl:for-each> " />
thx