Skip to content

Commit

Permalink
#1 opts to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 29, 2021
1 parent 64aeaf3 commit 1ad372a
Show file tree
Hide file tree
Showing 2 changed files with 71 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 @@ -105,6 +105,7 @@ public Collection<String> errors(final String locator) throws IOException {
Reverses.xsl("remove-conflicts.xsl"),
(before, after) -> !before.toString().equals(after.toString())
)
.with(Reverses.xsl("opts-to-boolean-expressions.xsl"))
.pass();
final XML out = new XMLDocument(
baos.toString(StandardCharsets.UTF_8.name())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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="opts-to-boolean-expressions" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:template match="o[opts]">
<xsl:variable name="o" select="."/>
<xsl:copy>
<xsl:apply-templates select="@*|node() except opts"/>
<xsl:for-each select="distinct-values(opts/opt/@x)">
<xsl:variable name="x" select="."/>
<xsl:element name="b">
<xsl:attribute name="x">
<xsl:value-of select="$x"/>
</xsl:attribute>
<xsl:for-each select="$o/opts">
<xsl:if test="position() &gt; 1">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:text>(</xsl:text>
<xsl:for-each select="opt">
<xsl:if test="position() &gt; 1">
<xsl:text> or </xsl:text>
</xsl:if>
<xsl:text>(</xsl:text>
<xsl:for-each select="tau">
<xsl:if test="position() &gt; 1">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:text>&#x1D70F;</xsl:text>
<xsl:variable name="parts" select="tokenize(@i, ':')"/>
<xsl:value-of select="$parts[1]"/>
<xsl:text>=</xsl:text>
<xsl:value-of select="text()"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</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 1ad372a

Please sign in to comment.