Search

Hello!

I'm building a comment section and using AddThis for the social aspect, but I'm running into a conflict with XSLT and the AddThis code.

The issue is that AddThis uses attributes with colons, causing a conflict with XSLT namespace rules. Any ideas on how to get around this?

Here's the AddThis Code

<div addthis:title='Title to Quote One…' addthis:url='www.site.com' class='addthis_toolbox addthis_default_style'>
              <a class='addthis_button_tweet' href=''></a>
            </div>

This Page has a solution:

http://stackoverflow.com/questions/16690185/using-colon-in-attribute-names-in-xsl-transformations

Basically, you can use XSL:text literal to supply escaped html text.

You need to declare the namespace in your xsl file's main tag, as you see the xsl namespace declared, then it's a matter of using the xsl:attribute method to apply the attribute

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:addthis="url/here">

<xsl:template match="data">

    <xsl:element name="div">
        <xsl:attribute name="addthis:title">Title to Quote One...</xsl:attribute>
        <xsl:attribute name="addthis:url">www.site.com</xsl:attribute>
        <xsl:attribute name="class">addthis_toolbox addthis_default_style</xsl:attribute>

        <xsl:element name="a">
            <xsl:attribute name="class">addthis_button_tweet</xsl:attribute>
            <xsl:attribute name="href">www.site.com</xsl:attribute>

            <xsl:text>Link Value Here</xsl:text>
        </xsl:element>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

@designermonkey,

Wow, you nailed it. Thanks a bunch!

@dexterous,

Your recommendation also is a good route, especially for quick fixes where dynamic content doesn't need to be pulled into the equation.

Thank you both!

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