When exporting XML from InDesign, I'd like assignments to show up as parent elements without manual intervention.

What I get now for a page that has three stories in two assignments:

<Root>
   <Story>
      <Headline>Foo</Headline>
      <Body>Bar</Body>
   </Story>
   <Story>
      <Headline>Foo2</Headline>
      <Body>Bar2</Body>
   </Story>
   <Story>
      <Headline>Foo3</Headline>
      <Body>Bar3</Body>
   </Story>
</Root>

What I'd like to get:

<Root>
   <Assignment>
      <Story>
         <Headline>Foo</Headline>
         <Body>Bar</Body>
      </Story>
      <Story>
         <Headline>Foo2</Headline>
         <Body>Bar2</Body>
      </Story>
   </Assignment>
   <Assignment>
      <Story>
         <Headline>Foo3</Headline>
         <Body>Bar3</Body>
      </Story>
   </Assignment>
</Root>

Use this xsl on export

<?xml version="1.0" encoding="UTF-8"?>

<xsl:template match="/">
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="Story">
    <Assignment>
        <xsl:copy-of select="."></xsl:copy-of>
    </Assignment>
</xsl:template>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.