将XML文件导入InDesign时出现命名空间错误
任务是将XML文件导入InDesign CS6,同时使用XSL转换处理该文件。为了将段落样式应用于导入的文本,通过XSLT添加属性“aid:pstyle”。一个非常简单的例子: 要导入的XML文件:将XML文件导入InDesign时出现命名空间错误,xml,xslt,adobe-indesign,Xml,Xslt,Adobe Indesign,任务是将XML文件导入InDesign CS6,同时使用XSL转换处理该文件。为了将段落样式应用于导入的文本,通过XSLT添加属性“aid:pstyle”。一个非常简单的例子: 要导入的XML文件: <?xml version="1.0" encoding="UTF-8"?> <Root> <Paragraph>This is my first XML-Import.</Paragraph> </Root> 这是我第一次导入X
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Paragraph>This is my first XML-Import.</Paragraph>
</Root>
这是我第一次导入XML。
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,我们得到
<?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>
这是我第一次导入XML。
可以将其导入InDesign,并获得所需的结果。
但是,当我们导入主输入并在导入过程中应用XSLT时,InDesign会抱怨名称空间错误。错误消息是“DOM Transformationsfehler:Ungültiges名称空间”(我们有一个德语InDesign版本,在英语中它应该有点像“DOM Transformation error:Unligal Namespace”。)
在导入中应用XSLT时,有什么线索可以导入我的XML吗?首先,我认为您对xmlns:aid使用了错误的名称空间IRI,但回顾其他示例时,我发现“InDesign/4.0/”和“used”都是空白的。实际上,后者似乎是正确的,因为插件SDK有一个匹配的定义 然后样式表version=“2.0”看起来有点大胆,我将其更改为“1.0”,但它仍然没有导入 最后我明白了:InDesign对名称空间非常挑剔。显然,名称空间必须在根元素处引入。以下版本适用于我的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>
非常感谢您的宝贵帮助-您的解决方案非常正确