0
Translate special characters at XML save/load
New Here
,
/t5/framemaker-discussions/translate-special-characters-at-xml-save-load/td-p/1248247
Feb 18, 2009
Feb 18, 2009
Copy link to clipboard
Copied
My XML files contain an element ([nbr], say) which must not be broken over two lines. In XML this element contains ordinary text with normal space, hyphen and/or slash characters. Because Frame's line break options are only settable at a document level (Document - Text Properties) I need to modify the content whenever the XML is passed into or out of Frame. (We use some basic r/w rules in this process, but most of our document adjustments are carried out by two XML stylesheets: xml2fm.xsl on load, fm2xml.xsl on save.)
I would like to enhance these stylesheets so that they translate the [nbr] element content, replacing any space characters with non-breaking spaces (and hyphens with non-breaking hyphens) in xml2fm, and the converse in fm2xml.
Our XML files are UTF-8. I have no difficulty coding this process so long as I know what "text" Frame will recognise as the non-breaking characters when it reads the XML and what it will write out when it saves it. I've seen some attempt to do this job with variables in the application template which are then imported into every document, and I'm not convinced that is the only or best way to go.
Anyone been here before me and can offer any pointers?
Thanks
T
I would like to enhance these stylesheets so that they translate the [nbr] element content, replacing any space characters with non-breaking spaces (and hyphens with non-breaking hyphens) in xml2fm, and the converse in fm2xml.
Our XML files are UTF-8. I have no difficulty coding this process so long as I know what "text" Frame will recognise as the non-breaking characters when it reads the XML and what it will write out when it saves it. I've seen some attempt to do this job with variables in the application template which are then imported into every document, and I'm not convinced that is the only or best way to go.
Anyone been here before me and can offer any pointers?
Thanks
T
TOPICS
Structured
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/framemaker-discussions/translate-special-characters-at-xml-save-load/m-p/1248248#M5233
Feb 18, 2009
Feb 18, 2009
Copy link to clipboard
Copied
Trevor,
I am not sure whether this helps you, but I use an EDD that has an element named nobreaksp that is used to insert a nonbreaking space. This element has no content. The EDD formats this element as character formatting with a prefix (or suffix) that is Frame's nonbreaking space.
I am assuming you are bring the XML into Frame and using the stylesheet to transform the XML structure into a structure compatible with your EDD. You could add an element like the above (you could also create a similar one for nonbreaking hyphens) to your EDD, then edit the xml2fm.xsl to transform the XML objects into these elements.
If I understand your situation correctly, your XML files have separate elements for nonbreaking spaces and nonbreaking hyphens, say nbr and nhybr. If so, the xsl stylesheets just simply need to replace the XML elements with the corresponding Frame elements. Or even simpler, name the Frame elements with the same names as used in the XML, then no translation is necessary.
The advantage to the above is that the element objects in the XML files are mirrored as elements in the Frame files. The job of inserting the correct character in the Frame files is done by the EDD, NOT by the xsl sheets. When you go from Frame to XML, the corresponding stylesheet does not need to recognize any special characters, just elements, which is what it does best.
Hope this helps,
Van
I am not sure whether this helps you, but I use an EDD that has an element named nobreaksp that is used to insert a nonbreaking space. This element has no content. The EDD formats this element as character formatting with a prefix (or suffix) that is Frame's nonbreaking space.
I am assuming you are bring the XML into Frame and using the stylesheet to transform the XML structure into a structure compatible with your EDD. You could add an element like the above (you could also create a similar one for nonbreaking hyphens) to your EDD, then edit the xml2fm.xsl to transform the XML objects into these elements.
If I understand your situation correctly, your XML files have separate elements for nonbreaking spaces and nonbreaking hyphens, say nbr and nhybr. If so, the xsl stylesheets just simply need to replace the XML elements with the corresponding Frame elements. Or even simpler, name the Frame elements with the same names as used in the XML, then no translation is necessary.
The advantage to the above is that the element objects in the XML files are mirrored as elements in the Frame files. The job of inserting the correct character in the Frame files is done by the EDD, NOT by the xsl sheets. When you go from Frame to XML, the corresponding stylesheet does not need to recognize any special characters, just elements, which is what it does best.
Hope this helps,
Van
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Trevor_Nicholls
AUTHOR
New Here
,
/t5/framemaker-discussions/translate-special-characters-at-xml-save-load/m-p/1248249#M5234
Feb 18, 2009
Feb 18, 2009
Copy link to clipboard
Copied
Thanks Van, it's a bit more complex than this and no, I don't have elements for the non breaking characters; I have elements containing particular types of data (like versions, filenames, and so on) which I do not want to break.
I do not want to put special non-breaking characters into the XML text - the break policy is dependent on the element type and having to control it at the lowest text level is anathema. However I have been able to solve the problem in two XML stylesheets and I'll provide the solution here in case it is useful to anyone else:
In the xml2fm stylesheet (losing some punctuation so as not to upset this forum's HTML):
> xsl:template match="version | filename"
xsl:copy
xsl:value-of select="translate(translate(.,' ',' '),'-','‑')" /
/xsl:copy
/xsl:template
And the converse in the fm2xml stylesheet:
> xsl:template match="version | filename"
xsl:copy
xsl:value-of select="translate(translate(.,' ',' '),'‑','-')" /
/xsl:copy
/xsl:template
This is only OK because the elements listed (and others that I haven't included in the example) have a simple text content model. Any elements with more complex content would require a bit more work, but the same principle would work.
Thanks
T
I do not want to put special non-breaking characters into the XML text - the break policy is dependent on the element type and having to control it at the lowest text level is anathema. However I have been able to solve the problem in two XML stylesheets and I'll provide the solution here in case it is useful to anyone else:
In the xml2fm stylesheet (losing some punctuation so as not to upset this forum's HTML):
> xsl:template match="version | filename"
xsl:copy
xsl:value-of select="translate(translate(.,' ',' '),'-','‑')" /
/xsl:copy
/xsl:template
And the converse in the fm2xml stylesheet:
> xsl:template match="version | filename"
xsl:copy
xsl:value-of select="translate(translate(.,' ',' '),'‑','-')" /
/xsl:copy
/xsl:template
This is only OK because the elements listed (and others that I haven't included in the example) have a simple text content model. Any elements with more complex content would require a bit more work, but the same principle would work.
Thanks
T
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Trevor_Nicholls
AUTHOR
New Here
,
/t5/framemaker-discussions/translate-special-characters-at-xml-save-load/m-p/1248250#M5235
Feb 18, 2009
Feb 18, 2009
Copy link to clipboard
Copied
It's highly amusing to see that (in my browser, anyway) both XSL code samples I have shown trigger inappropriate line breaks. The forum clearly needs a richer editing interface :-)
T
T
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
LATEST
/t5/framemaker-discussions/translate-special-characters-at-xml-save-load/m-p/1248251#M5236
Feb 19, 2009
Feb 19, 2009
Copy link to clipboard
Copied
Trevor,
I see now. You want the content of a particular element to be all (or maybe in part) on one line. I am glad you found a solution.
However, there may be some value in using half of my solution. That is, when going from XML to Frame, translate the various characters into elements, whose content (the nonbreaking characters) is governed by the EDD. Then from Frame to XML, translate the elements into characters. The one advantage I see is that it does not require knowing the bits and bytes that Frame stores for these nonbreaking characters. You enter them in the EDD using Frame's escape sequences. But this may be a minor advantage.
Good luck,
Van
I see now. You want the content of a particular element to be all (or maybe in part) on one line. I am glad you found a solution.
However, there may be some value in using half of my solution. That is, when going from XML to Frame, translate the various characters into elements, whose content (the nonbreaking characters) is governed by the EDD. Then from Frame to XML, translate the elements into characters. The one advantage I see is that it does not require knowing the bits and bytes that Frame stores for these nonbreaking characters. You enter them in the EDD using Frame's escape sequences. But this may be a minor advantage.
Good luck,
Van
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

