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" style="width:100%">
- <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>
- <b-search m:type="forum-search" m:orientation="hotrizontal">
- <field m:type="flat">
- search field
- <some-element>
- inside some element
- </some-element>
- </field>
- <button m:type="flat" m:label="text">
- search
- </button>
- </b-search>
- </root>
- <!-- XSL -->
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet version="2.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:bem="bem"
- xmlns:m="bem:m">
- <xsl:output method="html" version="4.0" encoding="UTF-8"/>
- <xsl:template match="*" mode="bem">
- <div>
- <xsl:apply-templates select="." mode="m"/>
- <xsl:value-of select="normalize-space(text()[1])"/>
- <xsl:apply-templates select="*" mode="bem"/>
- </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="@*[starts-with(name(), '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="@*[starts-with(name(), 'm:')]">
- <xsl:with-param name="name" select="$name"/>
- </xsl:apply-templates>
- </xsl:attribute>
- </xsl:template>
- <xsl:template match="@*[starts-with(name(), '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="@*"/>
- <xsl:function name="bem:block">
- <xsl:param name="block"/>
- <xsl:apply-templates select="$block" mode="bem"/>
- </xsl:function>
- <xsl:template match="/">
- <bem>
- <xsl:copy-of select="bem:block(*/*)"/>
- </bem>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement