Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- XML -->
- <?xml version="1.0" encoding="utf-8"?>
- <?xml-stylesheet href="bem.xsl" type="text/xsl" ?>
- <root xmlns:m="bem">
- <b-gallery m:type="interiors" m:size="small">
- <thumb>
- <b-image src="" m:size="small"></b-image>
- </thumb>
- <thumb>
- <b-image src="" m:size="small"></b-image>
- </thumb>
- <thumb>
- <b-image src="" m:size="small"></b-image>
- </thumb>
- </b-gallery>
- </root>
- <!-- XSL -->
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:func="http://exslt.org/functions"
- xmlns:exsl="http://exslt.org/common"
- xmlns:bem="bem"
- xmlns:m="bem:m"
- extension-element-prefixes="func">
- <xsl:output method="html" version="4.0" encoding="UTF-8"/>
- <xsl:template match="*" mode="bem">
- <div>
- <xsl:apply-templates select="." mode="m"/>
- <xsl:apply-templates select="*" mode="bem"/>
- <xsl:value-of select="text()"/>
- </div>
- </xsl:template>
- <xsl:template match="*" mode="m">
- <xsl:copy-of select="@*[namespace-uri() = '' and name() != 'class']"/>
- <xsl:choose>
- <xsl:when test="starts-with(local-name(), 'b-')">
- <xsl:apply-templates select="." mode="b"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="." mode="e"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="*" mode="b">
- <xsl:attribute name="class">
- <xsl:value-of select="local-name()"/>
- <xsl:apply-templates select="@m:*">
- <xsl:with-param name="name" select="local-name()"/>
- </xsl:apply-templates>
- </xsl:attribute>
- </xsl:template>
- <xsl:template match="*" mode="e">
- <xsl:param name="name">
- <xsl:variable name="ancestors" select="ancestor::*[starts-with(local-name(), 'b-')]"/>
- <xsl:value-of select="local-name($ancestors[position() = last()])"/>
- <xsl:text>__</xsl:text>
- <xsl:value-of select="local-name()"/>
- </xsl:param>
- <xsl:attribute name="class">
- <xsl:value-of select="$name"/>
- <xsl:apply-templates select="@m:*">
- <xsl:with-param name="name" select="$name"/>
- </xsl:apply-templates>
- </xsl:attribute>
- </xsl:template>
- <xsl:template match="@m:*">
- <xsl:param name="name"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text>_</xsl:text>
- <xsl:value-of select="local-name()"/>_<xsl:value-of select="."/>
- </xsl:template>
- <xsl:template match="@*"/>
- <func:function name="bem:block">
- <xsl:param name="block"/>
- <func:result>
- <xsl:apply-templates select="exsl:node-set($block)" mode="bem"/>
- </func:result>
- </func:function>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement