|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!-- |
| 3 | + * SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | +--> |
| 6 | +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="unnecessary-as" version="2.0"> |
| 7 | + <!-- |
| 8 | + Performs the reverse operation of "/org/eolang/parser/stars-to-tuples.xsl" |
| 9 | + --> |
| 10 | + <xsl:output encoding="UTF-8" method="xml"/> |
| 11 | + <xsl:function name="eo:all-alphas"> |
| 12 | + <xsl:param name="index"/> |
| 13 | + <xsl:param name="elem"/> |
| 14 | + <xsl:choose> |
| 15 | + <xsl:when test="$elem/@as=concat('α', string($index))"> |
| 16 | + <xsl:choose> |
| 17 | + <xsl:when test="$elem/following-sibling::o"> |
| 18 | + <xsl:sequence select="eo:all-alphas($index + 1, $elem/following-sibling::o)"/> |
| 19 | + </xsl:when> |
| 20 | + <xsl:otherwise> |
| 21 | + <xsl:sequence select="true()"/> |
| 22 | + </xsl:otherwise> |
| 23 | + </xsl:choose> |
| 24 | + </xsl:when> |
| 25 | + <xsl:otherwise> |
| 26 | + <xsl:sequence select="false()"/> |
| 27 | + </xsl:otherwise> |
| 28 | + </xsl:choose> |
| 29 | + </xsl:function> |
| 30 | + <xsl:template match="o[@base and not(starts-with(@base, '.')) and count(o[@as])=count(o)]"> |
| 31 | + <xsl:copy> |
| 32 | + <xsl:apply-templates select="@*"/> |
| 33 | + <xsl:choose> |
| 34 | + <xsl:when test="eo:all-alphas(0, o[1])"> |
| 35 | + <xsl:for-each select="o"> |
| 36 | + <xsl:variable name="elem"> |
| 37 | + <xsl:element name="o"> |
| 38 | + <xsl:for-each select="@*[name()!='as']"> |
| 39 | + <xsl:attribute name="{name()}" select="."/> |
| 40 | + </xsl:for-each> |
| 41 | + <xsl:apply-templates select="node()"/> |
| 42 | + </xsl:element> |
| 43 | + </xsl:variable> |
| 44 | + <xsl:apply-templates select="$elem"/> |
| 45 | + </xsl:for-each> |
| 46 | + </xsl:when> |
| 47 | + <xsl:otherwise> |
| 48 | + <xsl:apply-templates select="o"/> |
| 49 | + </xsl:otherwise> |
| 50 | + </xsl:choose> |
| 51 | + <xsl:apply-templates select="text()"/> |
| 52 | + </xsl:copy> |
| 53 | + </xsl:template> |
| 54 | + <xsl:template match="o[@base and starts-with(@base, '.') and count(o[@as])=count(o)-1]"> |
| 55 | + <xsl:copy> |
| 56 | + <xsl:apply-templates select="@*"/> |
| 57 | + <xsl:apply-templates select="o[1]"/> |
| 58 | + <xsl:choose> |
| 59 | + <xsl:when test="eo:all-alphas(0, o[position()=2])"> |
| 60 | + <xsl:for-each select="o[position()>1]"> |
| 61 | + <xsl:variable name="elem"> |
| 62 | + <xsl:element name="o"> |
| 63 | + <xsl:for-each select="@*[name()!='as']"> |
| 64 | + <xsl:attribute name="{name()}" select="."/> |
| 65 | + </xsl:for-each> |
| 66 | + <xsl:apply-templates select="node()"/> |
| 67 | + </xsl:element> |
| 68 | + </xsl:variable> |
| 69 | + <xsl:apply-templates select="$elem"/> |
| 70 | + </xsl:for-each> |
| 71 | + </xsl:when> |
| 72 | + <xsl:otherwise> |
| 73 | + <xsl:apply-templates select="o[position()>1]"/> |
| 74 | + </xsl:otherwise> |
| 75 | + </xsl:choose> |
| 76 | + <xsl:apply-templates select="text()"/> |
| 77 | + </xsl:copy> |
| 78 | + </xsl:template> |
| 79 | + <xsl:template match="node()|@*"> |
| 80 | + <xsl:copy> |
| 81 | + <xsl:apply-templates select="node()|@*"/> |
| 82 | + </xsl:copy> |
| 83 | + </xsl:template> |
| 84 | +</xsl:stylesheet> |
0 commit comments