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.

Remove unnecessary line breaks xml output file

Featured Replies

I'm a complete n00b (and probably stay a n00b because I don't use it very often) in creating a xsl file to use for creating a very simple xml file by making an export from Filemaker to xml.

But I found a sample file and changed this file a bit to get what I need.

I only have one issue I can't figure out hou to fix.

This is the xsl I use;

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fm="http://www.filemaker.com/fmpdsoresult" exclude-result-prefixes="fm">
  <xsl:output method="xml" indent="yes"/>
  
  <xsl:variable name="rename">
    <item from="EAN" to="EAN"/>
	<item from="Internal_Reference" to="Internal_Reference"/>
	<item from="Name" to="Name"/>
	<item from="Movie_Genre" to="Movie_Genre"/>
		
  </xsl:variable>

  <xsl:template match="/*">
    <items>
      <xsl:apply-templates select="fm:ROW"/>
    </items>
  </xsl:template>

  <xsl:template match="fm:ROW">
      <item>
        <xsl:apply-templates select="fm:EAN|fm:Internal_Reference|fm:Name|fm:Movie_Genre mode="rename"/>
      </item>
  </xsl:template>

  <xsl:template match="*" mode="rename" >
    <xsl:element name="{document('')//xsl:variable[@name = 'rename']/item[@from = local-name(current())]/@to}" >
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

It al works but I get an extra line feed after each tag;

The only think I need is to know how to prevent this.

This is the current output;

<?xml version="1.0" encoding="UTF-8"?>

<items>

<item>

<EAN>xxx</EAN>

<Internal_Reference>xxx</Internal_Reference>

<Name>xxx</Name>

<Movie_Genre>xxx</Movie_Genre>

</item>

</items>

And I would like to become this;

<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<EAN>xxx</EAN>
<Internal_Reference>xxx</Internal_Reference>
<Name>xxx</Name>
<Movie_Genre>xxx</Movie_Genre>
</item>
</items>

 

As addition, the xsl only works when selecting FMPDSORESULT, is it better to use FMPXMLRESULT instead ? And does this need a complete different xsl or is this a little change in the current xsl ?

TIA!

Edited by caphex

1. change this

indent="yes"

to

indent="no"

2. make sure there is NO whitespace that may come over in the XSL, especially in

<xsl:text>

</xsl:text>

Sometimes I remove ALL whitespace to verify that the process is correct. So the pretty "indented" XSL works just as well when you jam all the elements together:

<record><element><xsl:value-of select="something" /></element></record>

works just as well as:

<record>
   <element>
     <xsl:value-of select="something" />
   </element>
</record>

3. what are you using to view the result? some text editors will convert any end-of-line (from CR _or_ LF into CRLF, for example) and then you end up with double space.

beverly

  • Author

Beverly, thank you for your reply!

I almost don't dare to tell this, but I only opened the file with notepad++, didnt even try the default notepad... But in notepad everything is like it should be when with notepad++ I have the empty lines.

Strange thing is when opening the xml with xml notepad and saving the file and reopen with notepad++ the lines are gone..

So just leave it like it is I suppose then I guess.?

13 hours ago, caphex said:

I get an extra line feed after each tag

It's probably just a display problem. The default line separator in Windows is CRLF, and you may be seeing this as two line feeds. If you want to be sure, analyze your file in a text (or hex) editor.

 

13 hours ago, caphex said:

is it better to use FMPXMLRESULT instead ?

There are pros and cons to both. Strictly speaking, FMPDSORESULT is deprecated, so you should prefer FMPXMLRESULT for future-proofing. OTOH, it's been deprecated since version 7, so ...

 

13 hours ago, caphex said:

does this need a complete different xsl or is this a little change in the current xsl ?

It's not a trivial change.

  • 3 weeks later...

It's better to use FMPXMLRESULT because it is also the grammar for Import XML with FileMaker. (In addition to the Deprecated FMPDSORESULT!)

beverly

While the CRLF control characters does not matter for anything, but visuals, the wiggle below should be able to help you out:

tidy -i -xml -wrap 0 -newline lf -f /tmp/tidy_errors.txt -m your.xml
For Notepad++ you can just change the linebreak setting. If you are on Windows it's beyond my comprehension why you see CRLF as 2 linebreaks... 

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.