Invalid namespace error when importing XML into InDesign with XSLT stylesheet

Explorer ,
Dec 10, 2020

Copy link to clipboard

Copied

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

Views

43

Likes

Translate

Translate

Report

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

Invalid namespace error when importing XML into InDesign with XSLT stylesheet

Explorer ,
Dec 10, 2020

Copy link to clipboard

Copied

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

Views

44

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 10, 2020 0
Advisor ,
Dec 10, 2020

Copy link to clipboard

Copied

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 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2020 0
Explorer ,
Dec 28, 2020

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2020 0