Forum Replies Created
-
AuthorPosts
-
Theunis De Jong
MemberWordRTFImportPreferences? It comes with a couple of settings that may apply: preserveLocalOverrides, removeFormatting; perhaps a bit more.
Usually, I would set them to useful defaults in the UI, but ID Server has none of that …
Theunis De Jong
MemberThanks! (Me too!)
Theunis De Jong
MemberUse GREP.
bl will mark only the first character of a word starting with a lowercase. The b code marks a location, not an actual character, so it will work whether there is a space (or any other non-word character), or nothing at all.
Theunis De Jong
MemberAs with find & change, text variables, and section numbering, you cannot include real formatting in Index entries. There simply is no provision for formatting text that you input in the fields.
A possible workaround is to add 'formatting codes' into the index entries, and replace this with the correct formatting after generating the index. I would have suggested David's Automatically Format super/subscript trick (Auto Format Superscript and Subscript Numbers using GREP Styles), except … you happen to mention that “^7” yields a paragraph symbol. So his straightforward solution won't work.
The workaround is slightly more cumbersome to enter, but after that your index ought to be just fine every time you generate it.
1. Surround each of your superscripts with this: ^{text}, for example, to enter “x²” use “x^{2}”.
2. Surround each of your subscripts with this: _{text} — like this: “H_{2}O (water)”.
3. Create three character styles:
a. “HideMe” — set character color to “None” and horizontal scale to 1%.
b. “Super” — set character color to “Black”, horizontal scale to 100%, and position to Superscript.
c. “Sub” — same as Super, but with Subscript.
4. Add the following GREP styles to your Index Level 1 style (or any other style you are applying to the generated index text):
[_^]{.+?}
— apply character style “HideMe”.
(?<=^{).+?(?=})
— apply character style”Super”
(?<=_{).+?(?=})
— apply character style”Sub”.
The first character style effectively hides everything formatted with the codes ^{..} and _{..}, including all text in between. The Super and Sub styles make just the inside text visible again, and applies the correct formatting.
If you also want to include stuff like bold, italics, or underline, you can work out a similar system for these — all you have to do is add another code, and a character style that applies it.
Theunis De Jong
MemberMind you, XML is not the only way you can import database data. Look at Mail Merge, for example — it should be able to import your CSV (never used it, personally). You can use this if the transition from web text to InDesign is a straightforward one — i.e., import text, apply styles, print, go home.
But if you need to move stuff around, rename and group elements, or add custom texts, XML is the way.
I would recommend not to use InDesign to test your first XSTL transformations with. It doesn't appear to emit any useful errors, and if anything at all is wrong, the XML doesn't appear at all. So I use Saxon, a powerful XSLT processor, through the Kernow GUI. The screenshots are Windows, but it also works happily on my Mac. You edit your XML and XSLT with a good plain text editor (I use TextPad/Windows and TextWrangler/Mac) and process the files with Kernow. Since it has an output window of its own, you can immediately see what happens. You can dot your XSLT with debug stuff like <xsl:message>… thus far it works …</xsl:message>, and these will also appear in the Kernow output window. And if everything seems to work, you can try the same files in InDesign.
(Apart from the huge difference in XSLT versions — 1.0 for InDesign, which covers pretty much the basics and nothing else, where Saxon supports 2.0 plus a handful of extensions — there appear to be a few minor differences as well. My first try did work in Kernow/Saxon but failed in InDesign. I wouldn't know where to start looking for more info on that. Fortunately, there are dozens of different ways to do the same thing, even with bog standard XSLT 1.0.)
Theunis De Jong
MemberHow are you drawing that grid? Is it a table? (Because table lines do not obey the baseline grid, only text does.)
Theunis De Jong
MemberThe canonical XSLT reference is at https://www.w3.org/TR/xslt, and https://www.w3schools.com/xsl/ contains lots of useful snips and tips.
One thing is important: within seconds (well, minutes anyway) I had something up-and-running using the powerful “for-each-group” and “group-by” XSLT commands. However, InDesign didn't load the XSL at all — those commands are “XSLT 2.0”, and apparently InDesign only can handle XSLT 1.0. I didn't even get an error message …
So I had to take a short round-trip to the web — fortunately, your grouping problem is a well-known one (look for “Grouping with the Muenchian Method”, named after its inventor Steve Muench).
XSLT is a somewhat odd 'programming language', as it's not procedural/structured, like Javascript or Visual Basic, but rather functional (see https://en.wikipedia.org/wiki/C….._paradigms) — you define a set of 'rules' to apply, and the XSLT parser runs each of the rules on your input file.
It takes some mind-shifting to “get what you want”, because it would seem that most of the times you don't get anything at all … (when none of your rules appear to match anything of the input XML). So yeah, it takes some practice. But, in the words of Kay, “Oh yeah, it's worth it. … If you're strong enough.”
Theunis De Jong
MemberIt would require you to sort by the contact/department field in your spreadsheet, then move the department “one level up” around all of the contact groups with that same department field.
I have no idea if that's even possible.
Here is my idea instead
Let InDesign's XSLT parser do the hard work. If you import your original XML and apply this XSLT on importing, it will create a “dep_group” around a list of contacts for that department. The first element inside the dep_group is your original “department”, and this line is removed from the actual contact information.XSLT:
<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”https://www.w3.org/1999/XSL/Transform”>
<xsl:output method=”xml” version=”1.0″ encoding=”UTF-8″ indent=”yes”/><xsl:key name=”all_deps” match=”department” use=”.” />
<xsl:template match=”/”>
<xsl:element name=”contactlist”><xsl:apply-templates /></xsl:element>
</xsl:template><xsl:template match=”contactlist”>
<xsl:for-each select=”contact[department[generate-id() = generate-id(key('all_deps', .)[1])]]”>
<xsl:variable name=”cur_dep” select=”department” />
<xsl:element name=”dep_group”>
<xsl:element name=”department”><xsl:value-of select=”department” /></xsl:element>
<xsl:apply-templates select=”../contact[department=$cur_dep]” />
</xsl:element>
</xsl:for-each>
</xsl:template><xsl:template match=”department”></xsl:template>
<xsl:template match=”@*|node()”>
<xsl:copy>
<xsl:apply-templates select=”@*|node()” />
</xsl:copy>
</xsl:template></xsl:stylesheet>
(Warning: It seems some of the straight quotes are translated into 'curly' ones. Sorry 'bout that –you'll gonna have to weed them out one by one…)
Theunis De Jong
MemberThe DTD is not the correct place to add or remove items; it merely describes what goes where (and with what attributes, and in which order — etc.).
In fact this shows a shortcoming in your XML file: it ought to look like
<categoryHeader>
<contact>
<name><address><etc>
</contact>
<contact>
<name><address><etc>
</contact>
</categoryHeader>— but in this case, each contact has its own header. I'm sorry for your overheated brain, but … XSLT is the way to transform one type of XML into another type.
Can you post a small sample of what your XML looks like now, i.e., with the cat headers in the wrong position?
November 8, 2010 at 2:40 pm in reply to: Any Way to Synchronize a Book to Turn On/Off Layers? #57618Theunis De Jong
MemberIf Adobe is going to incorporate it into CS6, should I send them my bank account number? :D
Theunis De Jong
MemberThat's some funny stuff you got there — I think I'm gonna hold you to that promise!
All created on the computer?
Theunis De Jong
MemberI'm still in the dark what you mean with a 3d ebook cover. A 3d cover for an ebook? A 3d picture of an ebook cover? (Which would be, I think, a contradictio in terminus.) Or, what Mike suggests, a 3d image to display on the 'cover' of an ebook?
The main reason Photoshop was suggested above, would be that it's a real drawing package, where InDesign is (emphatically) not. Even with Illustrator you could do better.
But Photoshop is far from 'the only way'. If you need a free high quality bitmap editor, you could try GIMP; Inkscape is a free vector imaging application.
Here is the best I could do using only InDesign. I made a guess at the thickness ;) — but, of course, your ebook wouldn't have a “thickness”.

Theunis De Jong
Member.. That “join(“r”)” line near the top should actually read “join(“r”)”, to insert a return between each line. If I call up the Edit Post, I get the entire script on a single line :(
(It's of no effect to the inner workings of the script but I thought you might to try the sample as-is.)
Theunis De Jong
Member.. It's actually quite simple. This quickie fills a text frame (your cursor has to be in it) with all file names, from a certain starting folder, including files in sub(-sub-sub-sub)-folders. I would've posted it sooner, were it not that I (stupidly) tried it out on a folder that contained several thousands of files and folders … (It made me think I made a mistake somewhere…)
I also use another property of the 'getFiles' function: it can accept a simple text string, which is a file/folder mask such as “*.indd” or “*”, but it may also accept a function that somehow determines if a file or folder should be included. See the JS Help for details — in this case, all I do is check whether it is a file or a folder, and process only the ones I need.
For demonstration purposes, the entire folder structure gets saved into an array, so you can tell it works — you won't need any of the 'myResult' stuff.
It also demonstrates a crucial point on working with recursive functions: all variables inside that function need to be 'local', that is, declared using 'var xxx'. If not, its previous contents are overwritten by the function when it calls itself again!
result = processFolder (Folder(“/SomeFolder”));
app.selection[0].contents = result.join (“r”);
exit(0);function processFolder (startingPoint)
{
var tempFileList, tempFolderList, count;// only for debugging:
var myResult = [];
myResult.push (“rStarting with “+startingPoint.fsName);tempFileList = startingPoint.getFiles( function(x) { return x instanceof File; } );
// tempFileList now contains just files.
for (count=0; count<tempFileList.length; count++)
{
myResult.push (tempFileList[count].fsName);
processFile (tempFileList[count]);
}tempFolderList = startingPoint.getFiles( function(x) { return x instanceof Folder; } );
// tempFolderList contains just folders.
for (count=0; count<tempFolderList.length; count++)
{
myResult = myResult.concat(processFolder (tempFolderList[count]));
}
return myResult;
}function processFile (filename)
{
// .. do whatever you need to here.
}Theunis De Jong
MemberThe getFiles command returns anything that matches the mask you provide. In my example, I limited it to “”*.indd” to get only InDesign files, but — after some deliberating — I decided to add an explicit check because it may also return a Folder named “my files.indd”. (Don't laugh. Of course, me personally would never name a folder something like that, but you'd be amazed.)
This 'explicit check' is right below the for..loop:
if (myList[list] instanceof Folder)
continue;.. so the entire rest of the loop will be skipped ('continue') if the item under consideration is a folder. To make it scan for just folders, you need to make two crucial changes:
1. Change the pattern of 'getFiles' to (“*”), or omit it entirely — its default is in fact “*”. This will make it pick up any and all files and folders.
2. Change the line after the for.. command to
if (myList[list] instanceof File)
continue;
so the commands below it will only be processed when 'myList[list]' is a folder.
.. Or do i need to write a loop that goes into the folder and scans until it's done?
Well … it depends on what you are planning to do. If you want to 'process' all InDesign files in a certain folder and all the ones in subfolders, possibly nested, you need a recursive routine. If you look up “Recursive” in any good dictionary, it'll read “see Recursive” — that sums it up, I guess.
A good way would be:
1. Don't use the for..loop I gave as an example, but instead define two functions: processFile and processFolder.
2. Start your script with 'processFolder'.
3. Have this function scan for all files, and call the function 'processFile' for each.
4. Then have it scan for folders, and call the function 'processFolder' for each.
You see, hopefully, that #4 is the recursive part: if there is a folder inside your main (starting) folder, the function will call itself and process the files in there. If there is a folder in that, it will call itself and process the files in that one. Et cetera ad infinitum, or until all files & folders are processed — whatever comes first.
Tip: If part of your 'processFile' involves saving the file under a new name, take care not to process these in turn! That might lead to an endless loop, not quite ad infinitum but merely ad full hard disk.
-
AuthorPosts
