XML to InDesign Question: Whitespace.

Discussion in 'Design and Graphics' started by ppc_michael, Oct 1, 2007.

  1. Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #1
    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!
     
  2. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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.
     
  3. thread starter Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #3
  4. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
  5. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    OK, I through this together pretty quickly using random tags:

    Input XML using tab indenting:
    Code:
    <?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:
    Code:
    <?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:
    Code:
    <?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":
    Code:
    <?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.
     
  6. thread starter Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #6
    Wow, that's just what I need. Thank you so much for taking the time to write that for me!
     
  7. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7
    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.
     

Share This Page