XSLT Namespaces: Is there a work-around for including colons?
This is an open discussion with 3 replies, filed under Troubleshooting.
Search
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.
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