Hey Folks,
I just barely have started getting into this stuff, and I took on two projects simultaneously; one XML from MS Access and one XML from FMP.
One of the tricky things is I am also using a script to make 20 (or more) pages from a template page to import into, for both projects. The MS Access import I have working beautifully, everything goes where I want it. FMP not so much.
In order to get the script to work, I had to have a "flat" XML, so I have used the FMPDSORESULT method. What happens is that after the first page on the import, my nodes get out of order and there are blank text frames and everything gets spread further and further apart over subsequent pages.
I'll be honest, XML is brand new territory for me, just figuring stuff out from forums and tutorials, copying and pasting, so it's probably something dumb. I got the MS Access thing to work, so I just tried to literally force my file to be a copy as far as structure, added some tags (the "<Query2"> stuff) in what I believe to be the appropriate places, assuming I could make it work...but it doesn't. For this porject. Here's my XSLT that doesn't work.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<dataroot>
<Query2>
<xsl:for-each select="dataroot/Query2/*">
<xsl:value-of select="Query2/CR_Number"/>
<xsl:value-of select="Query2/Title"/>
<xsl:value-of select="Query2/Year_Created"/>
<xsl:value-of select="Query2/Medium_materials"/>
<xsl:value-of select="Query2/Owner_Credit_Line"/>
<xsl:value-of select="Query2/Provenance"/>
<xsl:value-of select="Query2/References"/>
<xsl:value-of select="Query2/Exhibitions"/>
<xsl:value-of select="Query2/Dimensionsheightcm"/>
</xsl:for-each>
</Query2>
</dataroot>
</xsl:template>
</xsl:stylesheet>
as compared to my XSLT that does work
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<dataroot>
<Query3>
<xsl:for-each select="dataroot/Query3/*">
<xsl:value-of select="Query3/LOT"/>
<xsl:value-of select="Query3/concatenated_artist_names"/>
<xsl:value-of select="Query3/Title"/>
<xsl:value-of select="Query3/concatenated_medium_date"/>
<xsl:value-of select="Query3/Credit_Line"/>
<xsl:value-of select="Query3/Value"/>
<xsl:value-of select="Query3/Minimum_Bid"/>
<xsl:value-of select="Query3/Participating"/>
</xsl:for-each>
</Query3>
</dataroot>
</xsl:template>
</xsl:stylesheet>
I am guessing you'll want to see the XML, too, but I signed a form saying I wouldn't share the data from FMP anywhere, so let me figure out how to mock up dummy data I guess and just share the other data here...unless you see a glaring problem in the XSLTs?
But here is the MS Access XML which worked great (I am going to trim it down and remove a few entries to save some space here, there are actually about 300 LOTS)
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Query3.xsl" generated="2019-07-25T12:40:08">
<Query3>
<LOT>101</LOT>
<concatenated_artist_names>Paul Davies</concatenated_artist_names>
<Title>L’ Horizon Fade</Title>
<concatenated_medium_date>Acrylic on paper, 2018</concatenated_medium_date>
<Credit_Line>Courtesy of the artist</Credit_Line>
<Value>4000</Value>
<Minimum_Bid>2000</Minimum_Bid>
<Participating>1</Participating>
<LOT>102</LOT>
<concatenated_artist_names>Andy Moses</concatenated_artist_names>
<Title>Geodesy 703</Title>
<concatenated_medium_date>Acrylic on canvas over circular wood panel, 2018</concatenated_medium_date>
<Credit_Line>Courtesy of the artist and William Turner Gallery</Credit_Line>
<Value>12500</Value>
<Minimum_Bid>6250</Minimum_Bid>
<Participating>1</Participating>
<LOT>103</LOT>
<concatenated_artist_names>Gwynn Murrill</concatenated_artist_names>
<Title>Twisting Cheetah 2</Title>
<concatenated_medium_date>Bronze, 2018</concatenated_medium_date>
<Credit_Line>Courtesy of the artist</Credit_Line>
<Value>9000</Value>
<Minimum_Bid>4500</Minimum_Bid>
<Participating>1</Participating>
<LOT>104</LOT>
<concatenated_artist_names>Tony DeLap</concatenated_artist_names>
<Title>Card Trick</Title>
<concatenated_medium_date>Acrylic on linen, 2014</concatenated_medium_date>
<Credit_Line>Courtesy of the artist and Parrasch Heijnen Gallery</Credit_Line>
<Value>35000</Value>
<Minimum_Bid>17500</Minimum_Bid>
<Participating>1</Participating>
<LOT>105</LOT>
<concatenated_artist_names>Kenton Nelson</concatenated_artist_names>
<Title>The Dive</Title>
<concatenated_medium_date>Watercolor, 2014</concatenated_medium_date>
<Credit_Line>Courtesy of the artist</Credit_Line>
<Value>8000</Value>
<Minimum_Bid>4000</Minimum_Bid>
<Participating>1</Participating>
</Query3>
</dataroot>
and of course the script for InDesign, as copied and then tweaked from https://medium.com/@Fjonan/multi-page-document-with-xml-in-indesign-2ab336ecf389
app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT,"Make20Pages_Auction3"); // makes the whole import one undoable action
function main () {
if (app.documents.length === 0) {
alert ("Please open a document.");
return;
}
app.scriptPreferences.enableRedraw = false;
var doc = app.activeDocument;
// Create Dummy pages
createDummyPages (20);
// Import XML
importXMLData (doc);
// Remove the blank pages in the document.
removeBlankPages (doc);
// Reverse Order of Pages (because due to how this all works its the wrong way around)
reversePageOrder (doc);
app.scriptPreferences.enableRedraw = true;
/* ADDS NEW PAGES WITH PLACEHOLDER CONTENT */
function createDummyPages(anzahldummies) {
for (i = anzahldummies; i >= 0; i--){
app.layoutWindows[0].activePage.duplicate (LocationOptions.AT_BEGINNING, app.layoutWindows[0].activePage);
}
}
/* IMPORTS XML DATA */
function importXMLData (doc) {
var myXMLImportPreferences = doc.xmlImportPreferences;
myXMLImportPreferences.importStyle = XMLImportStyles.mergeImport;
myXMLImportPreferences.createLinkToXML = false;
myXMLImportPreferences.allowTransform = true;
//myXMLImportPreferences.transformFilename = "F:\Curatorial\Registrar\TimCampbell\Auction2020\goodone\Query3.xsl
myXMLImportPreferences.repeatTextElements = true;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.ignoreUnmatchedIncoming = false;
myXMLImportPreferences.importTextIntoTables = false;
myXMLImportPreferences.ignoreWhitespace =true;
myXMLImportPreferences.importCALSTables = false;
myXMLImportPreferences.importToSelected = false;
doc.importXML(File("F:/Curatorial/Registrar/TimCampbell/Auction2020/goodone/Query3b.xml"));
}
/* REMOVES EMPTY PAGES FROM THE DOCUMENT */
function removeBlankPages (doc) {
var pages = doc.pages.everyItem().getElements().slice(0);
var i = pages.length;
while (i-- >1) {
!pages.allPageItems.length && pages.remove ();
}
!pages.allPageItems.length && pages != doc.pages[-1] && pages.remove ()
}
}
/* REMOVES EMPTY TEXTFRAMES FROM THE DOCUMENT */
function removeBlankFrames (doc){
var myStories = doc.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myTextFrames = myStories.textContainers;
for (j = myTextFrames.length - 1; j >= 0; j--) {
if (myTextFrames[j].contents.length <= 2){ // if you got TAGS inside a frame it will have a length of 2 even if no content has been imported - HACK
myTextFrames[j].remove();
}
}
}
}
/* REVERSE ORDER OF DOCUMENT PAGES */
function reversePageOrder(doc){
var pages = doc.pages.everyItem().getElements().slice(0);
var counter = pages.length;
while (counter-- >0) {
pages[counter].move (LocationOptions.BEFORE, pages[0]);
}
}
And all of that stuff works. So why not my other one?!?! It feels like it's a template thing? I am totally guessing.
Any help would be appreciated!!!!!
Thank you in advance!
Tim