Jump to content

Remove unnecessary line breaks xml output file


caphex

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

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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
  • Like 1
Link to comment
Share on other sites

This topic is 2955 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.