Jump to content

Preserve indenting in xml output from XLST


fmdataweb

This topic is 2598 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a xml export via XSLT working successfully to generate the correct XML file. I've noticed the XML file has no indenting which makes it hard to read - I was wondering if there's an easy way to include the indenting in the result xml file as part of the XSL file?

Here's what the XML looks like now:

<rss version="0.91">
<channel>
<title>Latest News</title>
<link>http://localhost/</link>
<description>Recent news articles</description>
<language>en-us</language>
<item>
<title>Slashdot</title>
<link>http://slashdot.org/</link>
<description>News for Nerds, stuff that matters</description>
</item>
</channel>
</rss>

 

I would like it to look like this:

<rss version="0.91">
    <channel>
        <title>Latest News</title>
        <link>http://localhost/</link>
        <description>Recent news articles</description>
        <language>en-us</language>
        <item>
            <title>Slashdot</title>
            <link>http://slashdot.org/</link>
            <description>News for Nerds, stuff that matters</description>
        </item>
    </channel>
</rss>

Here's what the XLS file looks like:

<xsl:stylesheet
    xmlns:fmp="http://www.filemaker.com/fmpxmlresult"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.1"
    exclude-result-prefixes='fmp' 
    >
    
    <xsl:output method="xml" 
        doctype-public="rss"
        doctype-system="http://www.scripting.com/dtd/rss-0_91.dtd"
        version="1.0" 
        encoding="UTF-8" 
        indent="yes"/>

    <xsl:template match="fmp:FMPXMLRESULT">

<rss version="0.91">
  <channel>
    <title>Latest News</title>
    <link>http://localhost/</link>
    <description>Recent news articles</description>
    <language>en-us</language>

        <xsl:for-each select="fmp:RESULTSET/fmp:ROW">
        
            <item>
                <title><xsl:value-of select="fmp:COL[1]/fmp:DATA" /></title>
                <link><xsl:value-of select="fmp:COL[2]/fmp:DATA" /></link>
                <description><xsl:value-of select="fmp:COL[3]/fmp:DATA" /></description>
            </item>

        </xsl:for-each>

  </channel>
</rss>

    </xsl:template>

</xsl:stylesheet>

Link to comment
Share on other sites

I've noticed the XML file has no indenting

​Yes, that is (yet another) quirk of the Xalan processor. You need to add the following attribute:

xalan:indent-amount="2"

to the <xsl:output> element and:

xmlns:xalan="http://xml.apache.org/xalan"

to the <xsl:stylesheet> element. Then change:

exclude-result-prefixes='fmp'

to:

exclude-result-prefixes='fmp xalan'
Edited by comment
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I always pipe output through

cat data.fmpxmlresult.xml | tidy -i -xml -wrap 0 -utf8

for indenting

 

If you export just a couple of hundred records white space does not really matter, but when you exceed a couple of thousands pr day, size actually makes a difference.

Edited by ggt667
Link to comment
Share on other sites

  • 4 weeks later...

If you are doing transfers across http, make sure you enable gzip in nginx or similar. If you are able to, i e

Edited by ggt667
Link to comment
Share on other sites

This topic is 2598 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.