PDA

View Full Version : FG Module XML to Formatted Text



LordEntrails
November 29th, 2016, 17:23
Sometime next year I am going to be wanting to take several large 5E modules I've created in FG and export them into formatted text (ultimately to PDF format). These modules have many hundreds of objects (stories, NPCs, encounters, items, etc) and I expect them each to be several hundreds of standard pages in length. Copy/paste into Word/text editor is not going to be reasonable.

I'd like to understand what tools are available that might be able to be converted, as well as what I might need to develop or define (as well as learn). I'm thinking something kind of like the Universal Character Exporter, XML DTD types of things etc. What about one of the current 5E parsers?

Is there some tool that takes XML of one format where I can provide a mapping to another XML format (i.e. FG XML to Word/PDF XML)?

NotRussellCrowe
November 29th, 2016, 17:35
Hi, LordEntrails!

You might look into XSLT (https://en.wikipedia.org/wiki/XSLT) if you are programmatically inclined. You don't need any special tools to use it, just find a good reference on the Internet.

Oxygen (https://www.oxygenxml.com/) used to be a good editor but I haven't used it for years so no idea now. There may also be some really good free ones. Eclipse (https://eclipse.org/ide/) may have a plug in too.

Good luck!

LordEntrails
November 29th, 2016, 17:58
Thanks, I'm no developer. Only language I ever knew much of was Fortran 77...

I do do a lot of scripting and some existing code modification along with using things like SQL queries from documentation. So I'm familiar at the 100,000 foot level :)

But, that's why I'm trying to plan ahead. So I have time to learn and figure things out. I figure that converting XML to a PDF can't be an unusual desire (as Google shows), but I'm just at a loss of where to start.

Anyone else with ideas or knowledge, thoughts would be appreciated.

knasser
November 29th, 2016, 19:04
Hi,

It's just a suggestion but I would say try out Scribus. It's Libre Software meaning there's no monetary cost to you and it both supports export to PDF and importing text with mark-up. If you're not used to Desk Top Publishing software there's a modest learning curve, but I believe it will be one of the quickest ways to do what you want. Create a document with a master page and the styles you like. Then take your XML files and turn them into a suitable markup. That may well be as simple as doing a search and replace on certain XML tags and a search and delete on others. Once done, you import it into Scribus (this is the big difference between something like a Word Processor where you're typing text into it and a DTP program where you're defining styles and sources and then attaching text to it from a source). It will turn your mark-up into the chosen paragraph styles.

Once done, export it as a PDF. (Or many).

Here are a couple of resources that will let you see if this is the sort of thing that you're looking for. Once you've read them you'll need to go back to the actual start and learn to use Scribus properly, but this will show you the areas relevant to whether you think it might work for you.

ocsmag.com/2015/11/24/layout-according-to-scribus-ii-using-styles-to-improve-your-workflow/
wiki.scribus.net/canvas/Working_with_text_frames


Note, Scribus actually saves its files as XML. You might, with some judicious search and replacing, actually be able to turn your XML export directly into a Scribus document. (Maybe. ;) ).

Hope this helps.

EDIT: The forum blocked me from pasting links so I stripped off the h and the t and the other t and then the p from the front of those two URLs. I'm naughty like that. ;)

damned
November 29th, 2016, 19:46
You are going to be doing a lot of copy and paste....

LordEntrails
November 29th, 2016, 20:39
You are going to be doing a lot of copy and paste....
No no no *G*

That's why I have to find a way to do it systematically/programmatically *G* I'm pretty confident at the moment that I can at least create a reasonable XLST and import the data into Word. The story entries look like they will come in by list Group I could then drag/drop or copy/paste them into a linear order. (That part looks pretty straight forward, see; https://msdn.microsoft.com/en-us/library/ee872374(v=office.12).aspx)

Right now I'm trying to figure out if Word 2013 has better tools or if I should take that approach. Scribus, Eclipse and various Apache project tools also look to be able to do it using XLS-FO, but that requires multiple application installs and custom application development (I think).

For anyone interested, attached is a sample campaign that can be used to see how the FG XML is laid out. I haven't done all the data types yet, but it would get most of the info out (except NPCs and Encounters, at the moment).

Still open to suggestions though as I'm not (yet) fixated on the Word/XLST approach. (Though I'm leaning that way because I know I will need to re-order elements once they are converted, so straight conversion to PDF won't help unless I then plan to edit the PDF.

Ikael
November 29th, 2016, 22:42
Alternative to XSL-FO would be princexml (https://www.princexml.com). You can run XSL-FO as commandline tool so there is no need to build appdev environment

LordEntrails
November 30th, 2016, 04:26
Well, looks like Word might not work anymore, found this as I got farther into it and it wasn't working as expected;


The removal of custom XML markup is the result of a United States court ruling on December 22, 2009. Customers who buy or license Word 2013 will find that the software does not include a particular custom XML tagging implementation.

Thanks for the prince xml link, I'm looking into that now.

Nylanfs
November 30th, 2016, 12:26
libreoffice

LordEntrails
November 30th, 2016, 16:13
libreoffice
Care to elaborate? Does Libre have xml/xslt capabilities Word doesn't?

kp9911
November 30th, 2016, 16:49
Programatically

1) Dump the db.xml into memory
2) Strip all XML tags
3) Remove all double white spaces
4) $$$

Nylanfs
November 30th, 2016, 17:08
All documents that LibreOffice create are OpenDocument (https://en.wikipedia.org/wiki/OpenDocument) format files which are all XML files. The schema for the OpenDocument xml structure can be found here (https://www.oasis-open.org/), so LibreOffice (and OpenOffice as well) should be able to open the FG xml files directly. Now converting them into something nice and pretty would take a bit of work.

Trenloe
November 30th, 2016, 17:16
This isn't record creation automation or anything, but when I need to do a lot of formatted text I:


Load all of the text up in Word, format it (using simple base formatting that FG supports - bold, underline, italic, etc.) and then save the document as HTML.
In Fantasy Grounds, create a number of empty Story entries (or records where you will store the formattedtext info). Exit FG.
Open up the db.xml file from the campaign you've just exited and copy paste the relevant set of "HTML" markup code in the document created in step #1 into the correct formattedtext control record in db.xml. Save db.xml. Check the XML syntax for db.xml.
Open up FG and check the records - FG will (mostly) ignore/remove any markup that it doesn't recognise.


You may need to do this a few times initially, as you learn what formatting in step #1 that FG recognises in step #4.

LordEntrails
November 30th, 2016, 21:53
@Nylafs, ok, thanks. Word files are actually XML docs as well. Well, technically, if that Word2007 article is right, they are a zip file that contains an xml file, a schema file and other embedded files. I think I can do the same thing you are suggesting with Word. But, I'll look at LO as well. Thanks :)

@Trenloe, I pretty much want to do that process in reverse. You can open up a db.xml file in Word 2013 no problem (image attached of what it looks like). It warns that it is going to remove the xml tags and offers to let you apply a xslt to it (that's what I'm working on developing now). It leaves you with all the text (indented like the xml) and no tags. I'm hoping the xslt will help with formatting and text styles, but I don't know yet.

@kp9911 and everyone,

Attached is a sample mod and a Word file that is the style template I'd like to get it into. Neither are complete at the moment, I have a few more object types to put into the module file as well as finish fleshing out the NPC example with an entry for each field etc. And the Word doc needs the styles cleaned up and entries made for the other object types.

LordEntrails
December 1st, 2016, 03:52
Anyone know what the proper format is for entering a variable in an XSL command?

The normal code looks something like this:
<xsl:for-each select="category">

It's possible to pass variables and such as I found in this example;
<xsl:value-of select="string($var1_instance/n2:ClinicalDocument/n2:title)"/>

I'm looking to do something roughly like:
<xsl:for-each select="id-*">
But I know that's not right.

I don't even know what to search google for to help my find acceptable syntax on this. Ideas appreciated.

NotRussellCrowe
December 1st, 2016, 11:10
Anyone know what the proper format is for entering a variable in an XSL command?

The normal code looks something like this:
<xsl:for-each select="category">

It's possible to pass variables and such as I found in this example;
<xsl:value-of select="string($var1_instance/n2:ClinicalDocument/n2:title)"/>

I'm looking to do something roughly like:
<xsl:for-each select="id-*">
But I know that's not right.

I don't even know what to search google for to help my find acceptable syntax on this. Ideas appreciated.

Been a long time since I've done XSLT so I'm not even sure if this is still valid or if there's a better way now, but try this:
https://www.w3schools.com/xml/ref_xsl_el_variable.asp

XSLT is not a programming language and therefore true variables do not exist. You can only set the value once per scope so it's more a constant than anything. However, you can set the value for each iteration in a for-each loop.

Here's a good example of parsing the hierarchy and setting a value from an attribute based on other attribute values in the nodes:
<xsl:variable name="header_pos" select="//row[cell[@num='1']='header']/@num"/>
i.e Get the row when the cell, with attribute num = '1', has a value of 'header'

I grabbed the above from
https://stackoverflow.com/questions/17320372/how-to-get-value-in-xml-attribute-through-xslt-to-variable

Think of <xsl:value-of .... /> as a PRINT command, you're just sending whatever text is there to the final output.

drvolk
December 1st, 2016, 11:54
Yes, as NotRussellCrowe wrote, XSLT works not as "common" programming languages. XSLT is a "functional language".
You have no "real" variables and also no "real" for-loop (there is no "break" condition or something like that or some kind of "goto" ...).

A lot of use cases you have to solve with recursive "template" calls. And you have to understand how you could navigate and filter xml nodes with "xpath" functionality.

I have some programming experience with C, perl, python and lua but when i tried XSLT it drives me crazy, becauce it is so different (more like LISP or something like that, i also dont realy understand ...)

I have sone examples how to "realize" a for-loop with "break" condition or how to realize a "real" variable, so if you interested in that, let me know :)

LordEntrails
December 1st, 2016, 15:26
Thanks guys. At least half of what you both said is over my head, but I'll see what I can figure out.

Trenloe
December 1st, 2016, 16:48
@Trenloe, I pretty much want to do that process in reverse. You can open up a db.xml file in Word 2013 no problem (image attached of what it looks like). It warns that it is going to remove the xml tags and offers to let you apply a xslt to it (that's what I'm working on developing now). It leaves you with all the text (indented like the xml) and no tags. I'm hoping the xslt will help with formatting and text styles, but I don't know yet.

Ah, sorry. I mis-read and thought you were trying to get formatted text info FG.

As an example, here's a quick extension I put together to export the calendar notes into XML: https://www.fantasygrounds.com/forums/showthread.php?18043-Feature-Request-Export-Calendar-Entries&p=141057&viewfull=1#post141057 Two posts further down is basic XSL to provide base formatting.

LordEntrails
December 1st, 2016, 21:44
Ah, sorry. I mis-read and thought you were trying to get formatted text info FG.

As an example, here's a quick extension I put together to export the calendar notes into XML: https://www.fantasygrounds.com/forums/showthread.php?18043-Feature-Request-Export-Calendar-Entries&p=141057&viewfull=1#post141057 Two posts further down is basic XSL to provide base formatting.
Excellent, that has the code I need;
<xsl:for-each select="root/log/*[starts-with(name(),'id-')]">

Now to see what I can do with it :)

kp9911
December 15th, 2016, 17:31
So this is what I have been able to do so far. Gotta admit once you get the hang of it, its fun!

LordEntrails
December 15th, 2016, 22:57
Awesome!

Looking good. Let me know what I can do to help. If you want, plan on me documenting how to reproduce this for the community.

This is going to save me so much time. I find adventure design so much easier in FG than any other tool (the only priority item I think FG is missing is spell checking).

Thanks again!
:)