This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Any good XML pretty printing tools?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

/ Stefan Bylund <steby@enea.se> was heard to say:
| Does anybody know if there are any good command-line driven XML pretty printing
| tools out there? Preferably, one should be able to configure the indentation
| width and maximal line length.

This works for me.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:saxon="http://icl.com/saxon";
                exclude-result-prefixes="saxon"
                version="1.0">

  <xsl:output method="xml" indent="yes"
              saxon:indent-spaces="2"/>

  <xsl:strip-space elements="*"/>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="comment()">
    <xsl:if test="not(preceding-sibling::node()[1][self::comment()])">
      <xsl:text>&#10;</xsl:text>
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
    <xsl:copy/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="processing-instruction()">
    <xsl:if test="not(preceding-sibling::node()[1][self::processing-instruction()])">
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
    <xsl:copy/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

                                        Be seeing you,
                                          norm

- -- 
Norman Walsh <ndw@nwalsh.com>      | The things we have most longed for
http://www.oasis-open.org/docbook/ | do not happen; or if they do, it
Chair, DocBook Technical Committee | is never at the time nor under the
                                   | circumstances when they could have
                                   | made us happiest.--La Bruyère
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.7 <http://mailcrypt.sourceforge.net/>

iD8DBQE+J2ZIOyltUcwYWjsRAkjqAKCbXNbUvD2/SI5J7Aua8h0CB1i1+QCcDJHO
UEduJWnBK427Ox48yd9+kxk=
=RoWW
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]