使用XSLT将动态XML转换为Adobe InDesign表

使用XSLT将动态XML转换为Adobe InDesign表,xml,xslt,adobe-indesign,Xml,Xslt,Adobe Indesign,我在将XML项列表转换为indesign表时遇到了麻烦。一个问题是计算行数,因为这是必需的,但不能作为简单计数()处理 InDesign表应如下所示: +------------+-------------+------------+ |ARTIKELNR |BEZEICHNUNG |VK1BRUTTO | +------------+-------------+------------+ | |TEXT1 | +-----

我在将XML项列表转换为indesign表时遇到了麻烦。一个问题是计算行数,因为这是必需的,但不能作为简单计数()处理

InDesign表应如下所示:

+------------+-------------+------------+ |ARTIKELNR |BEZEICHNUNG |VK1BRUTTO | +------------+-------------+------------+ | |TEXT1 | +------------+--------------------------+ ...
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<kategorie>
  <artikel>
<ARTIKELNR>              200151</ARTIKELNR>
<BEZEICHNUNG>ARTIST ONE - the first release</BEZEICHNUNG>
<TEXT1></TEXT1>
<VK1BRUTTO>13,9900</VK1BRUTTO>
  </artikel>
  <artikel>
<ARTIKELNR>              200153</ARTIKELNR>
<BEZEICHNUNG>ARTIST TWO - the second release</BEZEICHNUNG>
<TEXT1>Lorem ipsum dolor whatever...</TEXT1>
<VK1BRUTTO>13,9900</VK1BRUTTO>
  </artikel>
....
+------------+-------------+------------+ |ARTIKELNR | BEZEICHNUNG | VK1BRUTTO| +------------+-------------+------------+ ||文本1| +------------+--------------------------+ ... XML如下所示:

+------------+-------------+------------+ |ARTIKELNR |BEZEICHNUNG |VK1BRUTTO | +------------+-------------+------------+ | |TEXT1 | +------------+--------------------------+ ...
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<kategorie>
  <artikel>
<ARTIKELNR>              200151</ARTIKELNR>
<BEZEICHNUNG>ARTIST ONE - the first release</BEZEICHNUNG>
<TEXT1></TEXT1>
<VK1BRUTTO>13,9900</VK1BRUTTO>
  </artikel>
  <artikel>
<ARTIKELNR>              200153</ARTIKELNR>
<BEZEICHNUNG>ARTIST TWO - the second release</BEZEICHNUNG>
<TEXT1>Lorem ipsum dolor whatever...</TEXT1>
<VK1BRUTTO>13,9900</VK1BRUTTO>
  </artikel>
....

200151
艺术家一号-首次发布
13,9900
200153
艺术家二-第二版
Lorem ipsum dolor什么的。。。
13,9900
....
正如您所看到的,有时TEXT1是空的。在本例中:此项目没有第二行

因此,我写下了(InDesign)XSLT:


/xsl:variable>
失败: 1.行数计算不正确。 2.InDesign不会根据其结果构建表


有人能解释一下问题出在哪里,也许能给我一个正确的代码吗?

如果我猜对了,你想这样做(不相关的属性省略):

XSLT1.0

<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:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/kategorie">
    <Table aid:tcols="3" aid:trows="{count(artikel) + count(artikel/TEXT1[text()])}"> 
        <xsl:for-each select="artikel"> 
            <cell> 
                <xsl:value-of select="normalize-space(ARTIKELNR)"/>
            </cell> 
            <cell>
                <xsl:value-of select="BEZEICHNUNG"/>
            </cell>
            <cell>
                <xsl:value-of select="VK1BRUTTO"/>
            </cell>
            <xsl:if test="TEXT1/text()">
                <cell/>
                <cell>
                    <xsl:value-of select="TEXT1"/>
                </cell>
                <cell/>
            </xsl:if>
        </xsl:for-each> 
    </Table>
</xsl:template> 

</xsl:stylesheet>

应用于输入示例,结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:tcols="3" aid:trows="3">
   <cell>200151</cell>
   <cell>ARTIST ONE - the first release</cell>
   <cell>13,9900</cell>
   <cell>200153</cell>
   <cell>ARTIST TWO - the second release</cell>
   <cell>13,9900</cell>
   <cell/>
   <cell>Lorem ipsum dolor whatever...</cell>
   <cell/>
</Table>

200151
艺术家一号-首次发布
13,9900
200153
艺术家二-第二版
13,9900
Lorem ipsum dolor什么的。。。
谢谢。用更多的“魔法”,我做到了:

<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:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
<xsl:template match="/kategorie">
<Produkte>
<Tabelle aid:table="table" aid:tcols="3" aid:trows="{count(artikel) + count(artikel/TEXT1[text()])}" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/"> 

        <xsl:for-each select="artikel"> 

            <cell aid:table="cell" aid:ccolwidth="25.30" aid:pstyle="abs_Produkt_Artikelnummer" aid:cstyle="zei_Produkt_Artikelnummer" aid5:cellstyle="zel_Produkt_Artikelnummer" > 
                <xsl:value-of select="normalize-space(ARTIKELNR)"/>
            </cell> 
            <cell aid:table="cell" aid:ccolwidth="136.76" aid:pstyle="abs_Produkt_Bezeichnung" aid:cstyle="zei_Produkt_Bezeichnung" aid5:cellstyle="zel_Produkt_Bezeichnung">
                <xsl:value-of select="BEZEICHNUNG"/>
            </cell>
            <cell aid:table="cell" aid:ccolwidth="21.55" aid:pstyle="abs_Produkt_VKBrutto" aid:cstyle="zei_Produkt_VKBrutto" aid5:cellstyle="zel_Produkt_VKBrutto">
                <xsl:value-of select="substring(VK1BRUTTO, 0, string-length(VK1BRUTTO)-1)"/>
            </cell>
            <xsl:if test="TEXT1/text()">
                <cell aid:table="cell" aid:ccolwidth="25.30" aid:cstyle="zei_Produkt" aid5:cellstyle="zel_Produkt"></cell>
                <cell aid:table="cell" aid:ccolwidth="158.31" aid:ccols="2" aid:pstyle="abs_Produkt_Beschreibung" aid:cstyle="zei_Produkt_Beschreibung" aid5:cellstyle="zel_Produkt_Beschreibung">
                    <xsl:value-of select="TEXT1"/>
                </cell>
            </xsl:if>

        </xsl:for-each> 

    </Tabelle>
</Produkte>
</xsl:template>
</xsl:stylesheet>

提示:为了能够在InDesign中放置表格,表格周围必须有一个伪对象(即“Produkte”)


Johannes

您能发布转换的预期XML结果吗?