Permalink
Browse files

fix prettifying XML

Extracted XSLT to a separate file
  • Loading branch information...
1 parent 4025516 commit 5ada511a87d53cfaea3f763a948575c6fd8209b1 @mislav committed Feb 15, 2011
Showing with 49 additions and 49 deletions.
  1. +3 −49 lib/gorgeous.rb
  2. +46 −0 lib/pretty.xslt
View
@@ -9,8 +9,10 @@ def self.filename_to_format(filename)
end
end
+ PRETTY = File.expand_path('../pretty.xslt', __FILE__)
+
def self.pretty_xml(ugly)
- tidy = Nokogiri::XSLT DATA.read
+ tidy = Nokogiri::XSLT File.read(PRETTY)
tidy.transform(ugly).to_s
end
@@ -191,51 +193,3 @@ def filter_resultset(obj, key, idx = nil, deep = false)
end
end
end
-
-__END__
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="xml" encoding="UTF-8"/>
- <xsl:param name="indent-increment" select="' '"/>
-
- <xsl:template name="newline">
- <xsl:text disable-output-escaping="yes">
-</xsl:text>
- </xsl:template>
-
- <xsl:template match="comment() | processing-instruction()">
- <xsl:param name="indent" select="''"/>
- <xsl:call-template name="newline"/>
- <xsl:value-of select="$indent"/>
- <xsl:copy />
- </xsl:template>
-
- <xsl:template match="text()">
- <xsl:param name="indent" select="''"/>
- <xsl:call-template name="newline"/>
- <xsl:value-of select="$indent"/>
- <xsl:value-of select="normalize-space(.)"/>
- </xsl:template>
-
- <xsl:template match="text()[normalize-space(.)='']"/>
-
- <xsl:template match="*">
- <xsl:param name="indent" select="''"/>
- <xsl:call-template name="newline"/>
- <xsl:value-of select="$indent"/>
- <xsl:choose>
- <xsl:when test="count(child::*) > 0">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates select="*|text()">
- <xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
- </xsl:apply-templates>
- <xsl:call-template name="newline"/>
- <xsl:value-of select="$indent"/>
- </xsl:copy>
- </xsl:when>
- <xsl:otherwise>
- <xsl:copy-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-</xsl:stylesheet>
View
@@ -0,0 +1,46 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml" encoding="UTF-8"/>
+ <xsl:param name="indent-increment" select="' '"/>
+
+ <xsl:template name="newline">
+ <xsl:text disable-output-escaping="yes">
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="comment() | processing-instruction()">
+ <xsl:param name="indent" select="''"/>
+ <xsl:call-template name="newline"/>
+ <xsl:value-of select="$indent"/>
+ <xsl:copy />
+ </xsl:template>
+
+ <xsl:template match="text()">
+ <xsl:param name="indent" select="''"/>
+ <xsl:call-template name="newline"/>
+ <xsl:value-of select="$indent"/>
+ <xsl:value-of select="normalize-space(.)"/>
+ </xsl:template>
+
+ <xsl:template match="text()[normalize-space(.)='']"/>
+
+ <xsl:template match="*">
+ <xsl:param name="indent" select="''"/>
+ <xsl:call-template name="newline"/>
+ <xsl:value-of select="$indent"/>
+ <xsl:choose>
+ <xsl:when test="count(child::*) > 0">
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:apply-templates select="*|text()">
+ <xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
+ </xsl:apply-templates>
+ <xsl:call-template name="newline"/>
+ <xsl:value-of select="$indent"/>
+ </xsl:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+</xsl:stylesheet>

0 comments on commit 5ada511

Please sign in to comment.