0

The task is to import an XML-file into InDesign CS6 while processing that file with an XSL transformation. In order to apply paragraph-styles to the imported text, the attribute "aid:pstyle" is added via XSLT. A very brief example:

XML file to be imported:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
   <Paragraph>This is my first XML-Import.</Paragraph>
</Root>

XSL transformation:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
    version="2.0">

    <xsl:output indent="yes" method="xml"/>

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

    <xsl:template match="Paragraph">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:attribute name="aid:pstyle">
               <xsl:value-of select="'myParagraphStyle'"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

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

</xsl:stylesheet>

Running the XSLT externally on the input file, we get

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Paragraph xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:pstyle="myParagraphStyle">This is my first XML-Import.</Paragraph>
</Root>

which can be imported into InDesign with the desired results. However, when we import the primary input and apply the XSLT during that import, InDesign complains about wrong namespaces. The error message is "DOM-Transformationsfehler: Ungültiges Namespace" (we have a German InDesign version, in English it should be somewhat like "DOM-Transformation error: illegal namespace.")

Any clue how to get my XML imported while applying the XSLT on that import?

leu
  • 2,051
  • 2
  • 12
  • 25

1 Answers1

2

First I thought you were using the wrong namespace IRI for xmlns:aid, but revisiting other examples I found both "http://ns.adobe.com/Adobe InDesign/4.0/" with an additional blank and "http://ns.adobe.com/AdobeInDesign/4.0/" used. Actually the latter appears to be the correct one as the plugin SDK has a matching definition.

Then a stylesheet version="2.0" appeared a bit daring, I changed that to "1.0" but it still did not import.

FinallyI got it: InDesign is very picky about namespaces. Apparently the namespace must be introduced at the root element. The following version works with my InDesign CS6:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" version="1.0">

    <xsl:output indent="yes" method="xml"/>

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

    <xsl:template match="Root">
        <Root xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
            <xsl:apply-templates/>
        </Root>
    </xsl:template>

    <xsl:template match="Paragraph">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:attribute name="aid:pstyle">
                <xsl:value-of select="'myParagraphStyle'"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

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

</xsl:stylesheet>
Dirk
  • 666
  • 3
  • 6