Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Invalid namespace error when importing XML into InDesign with XSLT stylesheet

Explorer ,
Dec 10, 2020 Dec 10, 2020
When I attempt to import an XML file into InDesign using an XSLT stylesheet, I get a "DOM transformation error: Invalid namespace" error, and the import fails. I've looked through other posts related to namespaces, but none of them seem to deal directly with this scenario.
 
The XSLT is a simple script to replace relative table column widths with absolute sizes based on the column- and page-width of the InDesign template. The XSL includes aid and aid5 attributes, so I am declaring the namespace in both my XSLT stylesheet and my XML document. 
This is my XSLT stylesheet at its simplest form (I've stripped everything else away). Even this fails for me with the same error:

 

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
    xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">

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

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

</xsl:stylesheet>

Incidentally, when I transform the XML with this code outside of InDesign in a test environment, I can import the resulting XML with no issues, which leads me to believe that it's an InDesign issue rather than an XSLT issue. I've looked through my XSLT for another namespace that might not have gotten declared, but I can't find anything.

 

Any insight is greatly appreciated!

 

TOPICS
Import and export
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Guide , Dec 10, 2020 Dec 10, 2020

It is difficult when you yourself admit that you stripped everything else away.

Also it's been a while that I've written own InDesign XSLT, and it is past midnight so expect some wild guesses that I won't try out on my side.

 

At first sight, I'm missing an XMLDecl on top. I know it's optional, but …

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

 

An <xsl:output … could also help for completeness sake.

 

Then, I'm missing anything that would produce a root tag. Are you sure you have only a single book?

 

That ne

...
Translate
Explorer , Feb 18, 2021 Feb 18, 2021

For anyone that might encounter this issue in the future, I was able to resolve this issue following the example in the Plugin SDK in the XSL files located in:
source/sdksamples/xdocbookworkflow/examplefiles

 

Basically, here are the rules (and steps will follow):

  1. The source XML should not contain any namespaces. Those are introduced during import using the import stylesheet.
  2. The root element must contain the namespace definitions.
  3. Namespaces cannot be processed directly and must be added using variab
...
Translate
Guide ,
Dec 10, 2020 Dec 10, 2020

It is difficult when you yourself admit that you stripped everything else away.

Also it's been a while that I've written own InDesign XSLT, and it is past midnight so expect some wild guesses that I won't try out on my side.

 

At first sight, I'm missing an XMLDecl on top. I know it's optional, but …

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

 

An <xsl:output … could also help for completeness sake.

 

Then, I'm missing anything that would produce a root tag. Are you sure you have only a single book?

 

That nested book tag of your output that comes with extra namespaces. What is the inner apply-templates supposed to do with more attributes in the incoming book element? You might have a collision exactly there. I'd try explicit xsl:element and xsl:attribute instead of that <book …>, also suppress redundant xmlns:aid attributes on that tag.

 

A final suggestion: when looking in the SDK for some working examples, I saw a comment in the xdocbookworkflow/examplefiles about difficulties to produce the very namespace aid. There they've been jumping thru quite some hoops, maybe start from there and change the script until it breaks …

 

SDK download is somewhere below https://console.adobe.io/downloads 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2020 Dec 28, 2020

Thank you for your response. Today is the first day I've really had a chance to look at it or my code in any detail. The code I included here was a simplified version of what I'm using just to demonstrate what is happening with my root element (book).

 

After reading your response, I thought I had it figured out. The source XML file contained aid: and aid5: attributes, so we were already declaring the namespaces on the book element in source. I thought this might be causing the error, so I stripped it out just in case (since we were declaring them in the XSL stylesheet anyway). This eliminated the namespace error, but kicked out new errors for every aid: and aid5: attribute used, likely from the fact that we removed the namespace declaration on the root element.

 

Thinking I was on to something, I replaced every aid: and aid5: attribute in the source document with local attributes. And then used my XSL stylesheet to insert the aid: and aid5: attributes with the values from the local attributes. I reran the import with the XSL stylesheet, and it brought me full circle to the namespace error. So it doesn't like the namespace with the XSL stylesheet regardless of where or how it's declared. Which is so odd since it imports XML files just fine with the namespace when you don't use an XSL stylesheet.

 

Thank you for the reference in the SDK. I'll go looking for it. I had already downloaded the Scripting SDK for InDesign, but I couldn't find that in it, so it must be in one of the other SDKs. I'll keep looking. Thanks for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 18, 2021 Feb 18, 2021
LATEST

For anyone that might encounter this issue in the future, I was able to resolve this issue following the example in the Plugin SDK in the XSL files located in:
source/sdksamples/xdocbookworkflow/examplefiles

 

Basically, here are the rules (and steps will follow):

  1. The source XML should not contain any namespaces. Those are introduced during import using the import stylesheet.
  2. The root element must contain the namespace definitions.
  3. Namespaces cannot be processed directly and must be added using variables.

 

The XSL processing engine is pretty picky about namespaces, even Adobe's aid and aid5 namespaces. If they are in your source XML, you can import them without any issues if you don't associate an import XSL stylesheet. As soon as you add the stylesheet, the namespaces will break the import with an 'Invalid Namespace' error.

 

Adding the namespace to the root element is simply a workaround by creating a dummy attribute:

 

<xsl:template match="root-element">
<copy>
  <xsl:variable name="ns">aid</xsl:variable>
  <xsl:attribute
    name="{concat($ns, ':role')}"
    namespace="http://ns.adobe.com/AdobeInDesign/4.0/">force-namespace</xsl:attribute>
  <xsl:apply-templates/>
</copy>
</xsl:template>

 

 The aid:role attribute is not an actually an attribute, but must be used to force the namespace to behave correctly. Then for each attribute that uses a namespace, you construct the attribute in the same way:

 

<xsl:template match="root/title">
  <xsl:copy>
    <xsl:variable name="ns">aid</xsl:variable>
    <xsl:attribute
      name="{concat($ns, ':pstyle')}"
      namespace="http://ns.adobe.com/AdobeInDesign/4.0/">doc-title</xsl:attribute>
      <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

 

 In my case, my source XML contained widths for table cells, so I had to convert the attribute names to the correct aid namespace so that the InDesign tables could identify and apply the correct value. Here was how I handled that:

 

<xsl:template match="@cellwidth">
  <xsl:variable name="idns">aid</xsl:variable>
  <xsl:attribute name="{concat($idns,':ccolwidth')}"
    namespace="http://ns.adobe.com/AdobeInDesign/4.0/">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>  

 

For a full example of how this works, refer to the XSL stylesheets in the SDK location specified above.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines