Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Jul 25, 2011 @ 14:29
    Anthony Candaele
    0

    selectively adding text between <a> tags in Xslt

    Hi,

    I was working on an Xslt script, when the need arose to selectively put text between <a> href tags in Xslt.

    Say I have this Xslt code:

    <p><xsl:value-of select="$sometext"/><p>

    Depending on whether or not a user inputted an url in a macrocontainer, the text should be wrapped by a <a> tag:

    <p><a href="{$someurl}"><xsl:value-of select="$sometext"/></a><p>

    I was think first in solving this with  <xsl:attribute> but this only adds, by my knowing, attributes to the <a> element, unless there would also be an attribute like 'innerhtml' or something.

    An other solution maybe would be possible with an <xsl:template> , but I'm not an Xslt expert, hence my question on this forum :)

    Thanks for the advice,

    Anthony

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 25, 2011 @ 15:17
    Dirk De Grave
    1

    Anthony,

    I guess a simple xsl:choose would work?

    <p>
    <xsl:choose>
    <xsl:when test="$someurl">
    <a href="{$someurl}"><xsl:value-of select="$sometext"/></a>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$sometext"/>
    </xsl:otherwise>
    </xsl:choose>
    </p>

    Cheers,

    /Dirk

     

     

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 25, 2011 @ 15:32
    Anthony Candaele
    0

    Hi Dirk,

    Just tried your code, and my problem is solved :)

    Thanks a lot,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft