Skip to content

Commit

Permalink
#35 XSL.STRIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 21, 2014
1 parent 14a3ac4 commit 4c29b2a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/jcabi/xml/XSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
@Immutable
public interface XSL {

/**
* Strip spaces.
* @since 0.14
*/
XSL STRIP = XSLDocument.make(
XSL.class.getResourceAsStream("strip.xsl")
);

/**
* Transform XML to another one.
* @param xml Source XML document
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/com/jcabi/xml/strip.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<!--
* Copyright (c) 2009-2014, WOQUO.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are PROHIBITED without prior written permission from
* the author. This product may NOT be used anywhere and on any computer
* except the server platform of Woquo Inc. located at www.woquo.com.
* Federal copyright law prohibits unauthorized reproduction by any means
* and imposes fines up to $25,000 for violation. If you received
* this code accidentally and without intent to use it, please report this
* incident to the author by email.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:strip-space elements="*" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
12 changes: 12 additions & 0 deletions src/test/java/com/jcabi/xml/XSLDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ public void transformsIntoText() throws Exception {
);
}

/**
* XSL.STRIP can strip XML.
* @throws Exception If something goes wrong inside
*/
@Test
public void stripsXml() throws Exception {
MatcherAssert.assertThat(
XSL.STRIP.transform(new XMLDocument("<a> <b/> </a>")).toString(),
Matchers.containsString("<a>\n<b/>\n</a>")
);
}

}

0 comments on commit 4c29b2a

Please sign in to comment.