There is XML.
<file> <section> <comment># Секция заслешивания путей без слеша в конце</comment> <rule typename="RewriteRule" pattern="/([-a-zA-Z]+)" substitution="/$1/" flags="R=301,L" /> <rule typename="RewriteRule" pattern="/([-a-zA-Z]+)/([-a-zA-Z]+)" substitution="/$1/$2/" flags="R=301,L" /> <rule typename="RewriteRule" pattern="/([-a-zA-Z]+)/([-a-zA-Z]+)/([-a-zA-Z]+)" substitution="/$1/$2/$3/" flags="R=301,L" /> </section> <section> <comment># Секция преобразования URL в вызов контроллера</comment> </section> </file> At the exit after the conversion, we get the following text document.
# Секция заслешивания путей без слеша в конце RewriteRule ^/([-a-zA-Z]+)/([-a-zA-Z]+)/([-a-zA-Z]+)$ /$1/$2/$3/ [R=301,L] RewriteRule ^/([-a-zA-Z]+)/([-a-zA-Z]+)$ /$1/$2/ [R=301,L] RewriteRule ^/([-a-zA-Z]+)$ /$1/ [R=301,L] # Секция преобразования URL в вызов контроллера We have the following template for working with rule nodes
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- шаблон сопоставления с узлом rule --> <xsl:template match="rule"> <!-- Если у узла rule есть хотябы узел типа и он не пустой --> <xsl:if test="@typename != ''"> <!-- Выведем переход строки --> <xsl:text>
</xsl:text> <!-- Выведем из текущего узла тип правила --> <xsl:value-of select="@typename"></xsl:value-of> <!-- Начинаем паттерн с сопоставления с началом строки --> <xsl:text> ^</xsl:text> <!-- Выведем сам паттерн --> <xsl:value-of select="@pattern"></xsl:value-of> <!-- Завершим сопостовлением с концом строки --> <xsl:text>$ </xsl:text> <!-- Выведем правило подстановки --> <xsl:value-of select="@substitution"></xsl:value-of> <!-- Если есть свойство флагов и оно не пустое --> <xsl:if test="@flags != ''"> <!-- Начнем выводить блок флагов --> <xsl:text> [</xsl:text> <!-- Выведем влаги --> <xsl:value-of select="@flags"></xsl:value-of> <!-- Завершаем вывод флагов --> <xsl:text>]</xsl:text> </xsl:if> </xsl:if> </xsl:template> </xsl:stylesheet> The question of how to modify the template so that it would be in each pattern would remove the first slash from the strings like ^/([-a-zA-Z]+)$ and the pattern would look like this ^([-a-zA-Z]+)$
<xsl:output method="text" />so that it does not start escaping special characters where it is not necessary. - Pavel Mayorov