Jump to content
Server Maintenance This Week. ×

Escaping apostrophe character


3 Square

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

Recommended Posts

Hi,

I'm currently outputting an XML file using an XSLT stylesheet that contains a name and an amount figure. All works fine until the persons name contains an apostrophe.

The apostrophe causes the XML to become invalid. I've looked at the translate function and can't figure out how to get it to replace the apostrophe successfully with ' , even though I can get it to do "normal" characters!

At the moment I've got the following:

Works:

Doesn't work:

So in a nutshell, what is the best way to deal with the apostrophe problem? Is translate the way to go?

TIA,

Andy

Link to comment
Share on other sites

Thanks for the reply Tom.

I've tried replacing ' with ' earlier and I get the same result, a FileMaker error when trying to push the export through the XSLT file.

However, looking at it now, I'm not sure translate is the best function since I don't think it's going to replace a single character with multiple characters.

Link to comment
Share on other sites

No, translate is not the same as FileMaker's Substitute(). Perhaps you could create an unstored calculation field in FileMaker, with the character entity. That way you would already have translated it. Is this possibly a "smart quote"? That's even more problematic.

Link to comment
Share on other sites

Hi Fenton,

Thanks for the reply.

I thought about doing the replace in FileMaker first and did turn off smart quotes.

However, if I throw in the following calc: firstname & " " & Substitute ( surname ; "'" ; "'" )

FileMaker does sort things out but is rather too helpful by automatically dealing with the ampersand, as the XML then contains ' which isn't converted to anything!

Andy

Edited by Guest
Link to comment
Share on other sites

That's fixed it :wink2:

For anyone else with a similar problem, the combination of setting the FileMaker name field calculation to: Substitute ( firstname ; "'" ; "'" ) & " " & Substitute ( surname ; "'" ; "'") then changing the XSL element for the name field to has resulted in the apostrophe being replaced with ' which doesn't break the XML.

Cheers Fenton.

Link to comment
Share on other sites

It seems to me you are doing a lot of unnecessary work.

Early on in this thread, Fenton asked if you are using smart quotes, and you said you had turned them off. However, turning off smart quotes does not affect existing data. While you had them on, Filemaker converted every apostrophe into a right single quotation mark. Had you substituted these back into true apostrophes, Filemaker would have converted them into "'" entity references when exporting as XML.

Furthermore, I am not entirely convinced that an "apostrophe causes the XML to become invalid", unless you are transforming field contents into element names, e.g.

...

O'Shea>

Be as it may be, Filemaker does convert the apostrophe (and also the less-than, greater-than, quotation mark, ampersand - but curiously not the percent sign) characters into entity references.

Link to comment
Share on other sites

Comment, you're quite correct, turning smart quotes off doesn't affect existing data, which is why I removed the apostrophe and replaced it once I'd turned them off before re-testing. I guess I should have clarified as much for users who don't know that.

Interestingly, smart quotes on causes a further problem, in that the XML is OK in terms of validity in a text editor and browser but when used in Fusion Charts the apostrophe character is displayed as a€⁄™ where the 'a' is accented?!

This happens when smart quotes is on or off and only goes away when I implement smart quotes off, include and combine with substituting the apostrophe for ' in the calculation field. Note that, ' works equally well in the calculation and resulting output.

Any other combination breaks the XML, well as far a Fusion Charts is concerned anyway, or displays the wrong character.

Link to comment
Share on other sites

But if there are no smart quotes in your data, then you don't need to do anything. If your Name field contains "Jack O'Shea", the raw XML export (before any transformation) will be:

Jack O'Shea




That is if you are using the (deprecated) FMPDSORESULT grammar, as you seem to be. With FMPXMLRESULT grammar it would be:




Jack O'Shea

Surely, this is well-formed XML, even for Fusion Charts? It seems to me that Fusion Charts choking on a smart quote is a separate problem of character rendering, not to do with the XML being valid or not.

Link to comment
Share on other sites

Well, you'd think so but all I know is Fusion Charts throws an invalid XML error when the XML contains ' rather than '. It then throws the odd characters in when smart quotes is turned on but is OK with them off. So you're right, the XML is OK and displays fine in the browser, but breaks in Fusion Charts.

Anyway, the above fix works even if it's not the best.

Regarding, FileMaker's XML export using FMPDSORESULT I can't get ' to appear in the exported XML, in place of the apostrophe, when viewed in TextMate or TextEdit?

Link to comment
Share on other sites

Here's a screen shot showing the source and the resulting export. The first record contains a "plain" apostrophe. The second record was entered while smart quotes was turned on.

I think that if you are not getting ' to appear in the exported XML, it means you haven't really replaced the smart quotes with real apostrophes.

xml.png

Link to comment
Share on other sites

Trust me, I have really replaced the offending apostrophe with a plain one and vice versa with a 'real' one!

If I get FM to run an XML export and don't use a stylesheet I get your output.

Using the stylesheet removes ' and inserts an apostrophe so there's something going on with changes that are occurring through the stylesheet.

Link to comment
Share on other sites

Using the stylesheet removes ' and inserts an apostrophe

Yes, it does. It's part of the "rendering" that each XSLT processor does as it sees fit, and I don't think there's anything a user can do about it (interestingly, I get some processors to turn ' into an apostrophe too, while others beep at 'disable-output-escaping').

But it shouldn't be a problem, because a "plain" apostrophe MAY be used in well-formed XML:

http://www.w3.org/TR/xml/#syntax

I have downloaded Fusion Charts for Filemaker, but I don't see that it's using XML (and there's no problem with apostrophes), so you are probably using some other version? In any case, it seems the problem is in their implementation.

Link to comment
Share on other sites

Yes, you're right a plain apostrophe should be OK. It is definitely their implementation.

I should also mention that we're not using the free FileMaker version of Fusion Charts, although whether this is any different I don't know. I've noticed that there is an update available which may cure the issue. I'll try it and see.

Link to comment
Share on other sites

You should definitely try and get them to resolve this, because what you have now is the result of pure luck. As I said, not every XSLT processor will allow you to do this, and all it takes to break your workaround is for FMI to change their pick of the flavor.

Link to comment
Share on other sites

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