Skip to content

Commit

Permalink
#1 exprs to inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 30, 2021
1 parent 3f38313 commit a40ae0a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/polystat/far/Reverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Collection<String> errors(final String locator) throws IOException {
(before, after) -> !before.toString().equals(after.toString())
)
.with(Reverses.xsl("opts-to-boolean-expressions.xsl"))
.with(Reverses.xsl("expressions-to-inputs.xsl"))
.pass();
final XML out = new XMLDocument(
baos.toString(StandardCharsets.UTF_8.name())
Expand Down
87 changes: 87 additions & 0 deletions src/main/resources/org/polystat/far/expressions-to-inputs.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)
Copyright (c) 2020-2021 Polystat.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="expressions-to-inputs" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:template name="print">
<xsl:param name="pre" as="node()*"/>
<xsl:param name="next" as="node()?"/>
<xsl:choose>
<xsl:when test="$next">
<xsl:for-each select="$next/b">
<xsl:call-template name="print">
<xsl:with-param name="pre">
<xsl:copy-of select="$pre"/>
<a>
<xsl:attribute name="attr">
<xsl:value-of select="$next/@name"/>
</xsl:attribute>
<xsl:attribute name="x">
<xsl:value-of select="@x"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</a>
</xsl:with-param>
<xsl:with-param name="next" select="$next/following-sibling::o[b][1]"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:element name="input">
<xsl:for-each select="$pre">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:element name="expr">
<xsl:for-each select="$pre/a">
<xsl:if test="position() &gt; 1">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:value-of select="text()"/>
</xsl:for-each>
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="o[o[b]]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:call-template name="print">
<xsl:with-param name="pre" select="nothing"/>
<xsl:with-param name="next" select="o[b][1]"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="o[b]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except b"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

0 comments on commit a40ae0a

Please sign in to comment.