Link URL address of the text's tail in text nodes of xml file


/ Published in: XSLT
Save to your folder(s)

For *foo* node, if the node includes URL, link it.

e.g.

*before*: <code>&lt;foo&gt;bar http://example.com&lt;/foo&gt;</code>
*after*: <code>bar &lt;a href="http://example.com"&gt;http://example.com&lt;/a&gt;</code>


Copy this code and paste it in your HTML
  1. <xsl:template match="foo">
  2. <xsl:choose>
  3. <xsl:when test="contains(., 'http://')">
  4. <xsl:value-of select="substring-before(., 'http://')"/>
  5. <a><xsl:attribute name="href">http://<xsl:value-of select="substring-after(., 'http://')"/></xsl:attribute>http://<xsl:value-of select="substring-after(., 'http://')"/></a>
  6. </xsl:when>
  7. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  8. </xsl:choose>
  9. </xsl:template>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.