Created
May 10, 2012 14:40
-
-
Save xpathr/2653487 to your computer and use it in GitHub Desktop.
Alternate Text Attribute Splitter by tonyarnold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <xsl:stylesheet | |
| version="1.0" | |
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| xmlns:str="http://exslt.org/strings" | |
| extension-element-prefixes="str"> | |
| <xsl:template mode="html-filter" match="img/@alt | a/@title"> | |
| <xsl:variable name="keys-and-values" select="str:split(., ';; ')"/> | |
| <xsl:variable name="attribute-local-name" select="local-name()"/> | |
| <xsl:for-each select="$keys-and-values"> | |
| <xsl:choose> | |
| <xsl:when test="contains(., ':')"> | |
| <xsl:attribute name="{substring-before(., ':')}"> | |
| <xsl:value-of select="substring-after(., ':')"/> | |
| </xsl:attribute> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:attribute name="{$attribute-local-name}"> | |
| <xsl:value-of select="."/> | |
| </xsl:attribute> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:for-each> | |
| </xsl:template> | |
| <xsl:template mode="html-filter" match="@*"> | |
| <xsl:attribute name="{local-name()}"> | |
| <xsl:value-of select="."/> | |
| </xsl:attribute> | |
| </xsl:template> | |
| <xsl:template mode="html-filter" match="text()"> | |
| <xsl:value-of select="."/> | |
| </xsl:template> | |
| <xsl:template mode="html-filter" match="*"> | |
| <xsl:element name="{local-name()}"> | |
| <xsl:apply-templates mode="html-filter" select="@*" /> | |
| <xsl:apply-templates mode="html-filter" /> | |
| </xsl:element> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment