Jump to content
Server Maintenance This Week. ×

Help with XML Stylesheet formatting


NYC Newbie

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

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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