Xml: Difference between revisions

From miki
Jump to navigation Jump to search
(Created page with "* XSLT")
 
No edit summary
Line 1: Line 1:
== Links ==
* [[XSLT]]
* [[XSLT]]

== Tips ==
=== Format XML document ===
Using '''xmllint''' from package {{deb|libxml2-utils}} [https://stackoverflow.com/questions/16090869/how-to-pretty-print-xml-from-the-command-line]:

<source lang="bash">
xmllint --format doc.xml
</source>

Using '''xsltproc''' and XSLT stylesheet. This requires an intermediate XSLT document:
<source lang="bash">
cat > indent.xslt << __HERE__
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
__HERE__
xsltproc indent.xslt doc.xml
</source>

Revision as of 17:42, 8 November 2019

Links

Tips

Format XML document

Using xmllint from package libxml2-utils [1]:

xmllint --format doc.xml

Using xsltproc and XSLT stylesheet. This requires an intermediate XSLT document:

cat > indent.xslt << __HERE__
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml"  encoding="UTF-8" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>
__HERE__
xsltproc indent.xslt doc.xml