Monday, 8 December 2014

Cannot process elements inside cdata



I'm trying to edit the link within the CDATA:



<paragraph>
<![CDATA[
<strong><a href="http://ift.tt/1wrVnSp">Article Title</a></strong>Article Excerpt.
]]>
</paragraph>


The goal is to change paragraph to


and at the same time, add additional tags inside the link. For example, the desired output can be: (not all the have links in it, some contains only text)



<p>
<strong><a href="http://ift.tt/1GaOxA3" style="font-size:1.1em; color:#067ab4; line-height:100%">Article Title</a></strong>Article Excerpt.
</p>


I have tried the following code but it didn't work.



<xsl:template match="paragraph">
<xsl:copy-of select="@*"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<p>]]></xsl:text>
<xsl:value-of select="." disable-output-escaping="yes"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</p>]]></xsl:text>
</xsl:template>

<xsl:template match="text()[contains(.,'&lt;a href=&#34;') and contains(.,'&#34;>')]">

<xsl:variable name="link" select="substring-before(substring-after(., '&lt;a href=&#34;'), '&#34;>')"/>

<xsl:text disable-output-escaping="yes"><![CDATA[<a href="]]></xsl:text>
<xsl:value-of disable-output-escaping="yes" select="$link"/>
<xsl:text disable-output-escaping="yes"><![CDATA[&tracking_id=12345" ]]></xsl:text>
<xsl:value-of select="$link_style"/>
<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
<xsl:apply-templates select="child::node()"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</a>]]></xsl:text>

</xsl:template>

No comments:

Post a Comment