Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Preserve indenting in xml output from XLST

Featured Replies

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>

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

  • Author

Thank you - that works great.

  • 1 year later...
  • Newbies

thanks #comment

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

  • 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

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.