PDA

View Full Version : XML to InDesign Question: Whitespace.




ppc_michael
Oct 1, 2007, 05:52 PM
I'm working with InDesign CS3.

I've written a document in XML and I'm trying to bring it over to InDesign to format it for print. I've imported it and assigned the tags to styles, and I think that's pretty cool.

But! I have a problem with whitespace. In my XML file, I've done things like indented child elements (am I not supposed to do that?), and those tabs show up in InDesign as whitespace in the text. Oops.

Is there a way I can make those tabs go away in InDesign, while preserving them in the XML file (because it looks nicer, for when I go to edit it)? I've read about XSLT but wouldn't know how to write one, is that my only option? I'm hoping for some sort of checkbox in InDesign. ;)

Thanks!



angelwatt
Oct 1, 2007, 09:09 PM
Something like that is definitely application specific. I've never used inDesign so not sure how it works, but I do use XML a bit and know whitespace matters. If no one knows a way to tell InDesign to treat whitespace differently I could probably come up with an XSLT for you ... maybe. I haven't tried your specific situation, but I think it can be fairly easily done.

ppc_michael
Oct 2, 2007, 08:46 PM
Thanks for the reply.

I tried this XSLT from http://www.biglist.com/lists/xsl-list/archives/200210/msg00544.html but it didn't really work the way I wanted it to. :/

angelwatt
Oct 2, 2007, 09:17 PM
Thanks for the reply.

I tried this XSLT from http://www.biglist.com/lists/xsl-list/archives/200210/msg00544.html but it didn't really work the way I wanted it to. :/

If you post the xml I can take a go at it, unless it's too large, then a reasonable snippet will do.

angelwatt
Oct 2, 2007, 09:48 PM
OK, I through this together pretty quickly using random tags:

Input XML using tab indenting:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<test>
<el>text</el>
<li>
<do>something</do>
</li>
<am>ahahfn</am>
<sd>dc thif md</sd>
</test>

The XSLT to transform the above XML:
<?xml version="1.0" encoding="UTF-8"?>
<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="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

The Output XML that results, indented with spaces only:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<el>text</el>
<li>
<do>something</do>
</li>
<am>ahahfn</am>
<sd>dc thif md</sd>
</test>

The resulting XML if you change the output tag's attribute "indent" to "no":
<?xml version="1.0" encoding="UTF-8"?>
<test><el>text</el><li><do>something</do></li><am>ahahfn</am><sd>dc thif md</sd></test>

Hope that works for you.

ppc_michael
Oct 4, 2007, 01:49 PM
Wow, that's just what I need. Thank you so much for taking the time to write that for me!

angelwatt
Oct 4, 2007, 05:20 PM
Wow, that's just what I need. Thank you so much for taking the time to write that for me!

Cool, glad that was what you needed. Just out of curiosity, which output style did you end up using? With indent set to "yes" or "no"? It may help someone down the line to know the specifics.