1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
extension-element-prefixes="php"
exclude-result-prefixes="xsl php">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:variable name="schemaPath" select="'https://raw.github.com/magento/magento2/master/app/code/Mage/Core/etc/layouts.xsd'"/>
<!-- Copy nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Remove translate attribute attribute -->
<xsl:template match="@translate[.!='true']">
<xsl:apply-templates select="node()"/>
</xsl:template>
<!-- Move translate attribute to exact node -->
<xsl:template match="*[../@translate]">
<xsl:variable name="translate" select="../@translate"/>
<xsl:choose>
<xsl:when test="@name=$translate">
<xsl:copy>
<xsl:attribute name="translate">true</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:when>
<xsl:when test="contains($translate, ' ')">
<xsl:call-template name="tokenize">
<xsl:with-param name="translate" select="$translate" />
<xsl:with-param name="separator" select="' '" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Subroutine for translate it it contains separator -->
<xsl:template name="tokenize">
<xsl:param name="translate"/>
<xsl:param name="separator"/>
<xsl:variable name="first-item" select="normalize-space(substring-before(concat($translate, $separator), $separator))" />
<xsl:choose>
<xsl:when test="$first-item=@name">
<xsl:copy>
<xsl:attribute name="translate">true</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:when>
<xsl:when test="$first-item">
<xsl:call-template name="tokenize">
<xsl:with-param name="translate" select="substring-after($translate, $separator)" />
<xsl:with-param name="separator" select="$separator" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>