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.

Help with XML Stylesheet formatting

Featured Replies

I would like to export to XML using an XSL stylesheet.

But I'm such a newbie and unsuccessfully learning my way around the "for-each" and "value-of" verbiage.

And I'm not doing such a great job with spacing either. I need a carriage return for each line and a single space indent here and there. The indent="yes" results in two carriage returns - one of them a fully blank line.

There are 3 fields for each record I'm exporting - itemID, title and category.

The output must conform to the following format -

<?xml version="1.0" encoding="ISO-8859-1"?>

<Website>

<UploadList>

<itemID> the item goes here </itemID>

<title> the title goes here </title>

<category> category goes here </category>

</UploadList>

</Website>

So far I've got on my incorrectly formatted XSL stle sheet -

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

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:fmp="http://www.filemaker.com/fmpxmlresult"

exclude-result-prefixes="fmp">

<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" omit-xml-declaration="no" />

<xsl:template match="/">

<Website>

<UploadList>

<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">

<xsl:for-each select="fmp:COL">

<itemID><xsl:value-of select="fmp:DATA"/></itemID>

<title><xsl:value-of select="fmp:DATA"/></title>

<category><xsl:value-of select="fmp:DATA"/></category>

</xsl:for-each>

</xsl:for-each>

</UploadList>

</Website>

</xsl:template>

</xsl:stylesheet>

I would be grateful for any help. I've been googling and studying sample files but not gleaning much explanation.

Try it this way:


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



<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:fmp="http://www.filemaker.com/fmpxmlresult"

exclude-result-prefixes="fmp">



<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />



<xsl:template match="/">



<Website>

<UploadList>

<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">

	<itemID><xsl:value-of select="fmp:COL[1]"/></itemID>

	<title><xsl:value-of select="fmp:COL[2]"/></title>

	<category><xsl:value-of select="fmp:COL[3]"/></category>

</xsl:for-each>

</UploadList>

</Website>



</xsl:template>

</xsl:stylesheet>

Note that this assumes you are exporting the three fields - itemID, title and category - in this order.

  • Author

Wow. Thank you so much.

By the way, I tried it with <xsl:value-of select="fmp:COL[1]/fmp:DATA" /> too. Same result.

Any reason I'd choose with or without "fmp:DATA" suffix?

Also, I'm still at sea with the spacing issue.

I'm getting two carriage returns when I specify indent="yes" - ergo getting a full empty line between each line of code.

I get NO spacing at all when I specify indent="no".

Also the resulting XML needs to indent one or two spaces on a few lines as follows (sorry the spacing format didn't show up on my original post) -

<?xml version="1.0" encoding="ISO-8859-1"?>

<Website>

<UploadList>

<itemID> the item goes here </itemID>

<title> the title goes here </title>

<category> category goes here </category>

</UploadList>

</Website>

Ever so grateful for the help!

  • Author

Ugh, it didn't show up again on my reply!

Ok, here's another go at it -

<?xml version="1.0" encoding="ISO-8859-1"?>

<Website>

*space*<UploadList>

*space**space*<itemID> the item goes here </itemID>

*space**space*<title> the title goes here </title>

*space**space*<category> category goes here </category>

*space*</UploadList>

</Website>

Any reason I'd choose with or without "fmp:DATA" suffix?

It makes no practical difference (here): xsl:value-of returns the text nodes of selected element and its children. Since the COL element has no text node of its own and only one DATA element, the result is the same (as long as it's not a repeating field).

Also, I'm still at sea with the spacing issue.

Try removing all spaces, tabs and carriage returns from the XSL stylesheet (esp. if you have copied it from here - keep an eye on other invisible characters, too).

Also the resulting XML needs to indent one or two spaces on a few lines

For what purpose? You are requesting an XML result - and an XML document is equally valid with or without indents.

  • Author

Removing spaces, tabs, returns still yields the same two carriage returns when indent="yes".

As for the reasons for a little space or two at the beginning of each line, eh, I dunno. I'm just following the API documentation example I was given - the provided sample XML shows small indentations.

Well, lemme try to post the XML file to the webservice and see if it is successful or if I get errors because of the spacing issue.

Again, thanks for all the help. It's been a tremendous aid.

Sorry, I have misread your post - I thought you had returns in the data itself. It's probably just a problem in displaying the document. On Windows, a "new line" is CRLF. It looks like the application you are using to view the result adds a new line for both CR and LF.

In any case, it should make no difference to the receiving application (unless the web service people don't have a clue...).

Speaking of that, the format is kinda weird: one would expect an <item> element wrapping each triplet in the list.

  • Author

The XML file was accepted as is successfully. No need to work out the additional empty lines and missing tabs. Thanks for the help!

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.