将 XML 文件导入 InDesign 时出现命名空间错误 [英] Namespace error when importing XML-file into InDesign

查看:29
本文介绍了将 XML 文件导入 InDesign 时出现命名空间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务是将 XML 文件导入 InDesign CS6,同时使用 XSL 转换处理该文件.为了将段落样式应用于导入的文本,通过 XSLT 添加了属性aid:pstyle".一个非常简短的例子:

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 文件:

XML file to be imported:

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

XSL 转换:

<?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>

在输入文件外部运行 XSLT,我们得到

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>

可以导入到 InDesign 中并获得所需的结果.但是,当我们导入主要输入并在导入期间应用 XSLT 时,InDesign 会抱怨命名空间错误.错误消息是DOM-Transformationsfehler: Ungültiges Namespace"(我们有一个德语 InDesign 版本,英文应该有点像DOM-Transformation error:非法命名空间.")

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.")

在对导入应用 XSLT 时如何导入我的 XML 有任何线索吗?

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

推荐答案

一开始我以为你对 xmlns:aid 使用了错误的命名空间 IRI,但是重新审视其他例子我发现两个http://ns.adobe.com/Adobe InDesign/4.0/" 带有额外的空白和 "http://ns.adobe.com/AdobeInDesign/4.0/" 使用.实际上后者似乎是正确的,因为插件 SDK 具有匹配的定义.

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.

然后样式表 version="2.0" 显得有点大胆,我将其更改为 "1.0" 但它仍然没有导入.

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

我终于明白了:InDesign 对命名空间非常挑剔.显然命名空间必须在根元素中引入.以下版本适用于我的 InDesign CS6:

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>

这篇关于将 XML 文件导入 InDesign 时出现命名空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆