我在将XML项目列表转换为indesign表时遇到了麻烦。一个问题是计算行数,因为这是必需的,但不能作为简单的count()处理。
InDesign表应如下所示:
+------------+-------------+------------+ |ARTIKELNR |BEZEICHNUNG |VK1BRUTTO | +------------+-------------+------------+ | |TEXT1 | +------------+--------------------------+ ...
XML看起来像这样:
<?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>
....
正如您所看到的,TEXT1有时是空的。在这种情况下:此项目没有第二行。
所以我写下了这个(InDesign)XSLT:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" exclude-result-prefixes="xs">
<xsl:output method="xml" encoding="utf-8" indent="no"/>
<xsl:strip-space elements="ARTIKELNR"/>
<xsl:template name="rowcount">
<xsl:param name="rows"/>
<xsl:for-each select="article">
<xsl:if test="TEXT1 != ''">
<xsl:call-template name="rowcount">
<xsl:with-param name="rows" select="$rows + 1" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="/kategorie">
<xsl:variable name="rows"><xsl:call-template name="rowcount"/>
/xsl:variable>
<Table aid:tcols="3" aid:trows="$rows" aid:table="table" 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:crows="1" aid:ccols="1" aid:ccolwidth="25.30pt" aid:pstyle="abs_Produkt_Artikelnummer" aid:cstyle="zei_Produkt_Artikelnummer" aid5:cellstyle="zel_Produkt_Artikelnummer" aid:theader="">
<xsl:value-of select="substring(ARTIKELNR, string-length(ARTIKELNR) - 6)"/>
</cell>
<cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.76pt" aid:pstyle="abs_Produkt_Bezeichnung" aid:cstyle="zei_Produkt_Bezeichnung" aid5:cellstyle="zel_Produkt_Bezeichnung" aid:theader="">
<xsl:value-of select="BEZEICHNUNG"/>
</cell>
<cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="21.55pt" aid:pstyle="abs_Produkt_VKBrutto" aid:cstyle="zei_Produkt_VKBrutto" aid5:cellstyle="zel_Produkt_VKBrutto" aid:theader="">
<xsl:value-of select="substring(VK1BRUTTO, string-length(VK1BRUTTO), string-length(VK1BRUTTO)-2)"/>
</cell>
<xsl:variable name="freitext" select="TEXT1"/>
<xsl:if test="$freitext != ''">
<cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:pstyle="abs__empty" aid:cstyle="zei__empty" aid5:cellstyle="zel__empty" aid:theader="">
</cell>
<cell aid:table="cell" aid:crows="1" aid:ccols="2" aid:pstyle="abs_Produkt_Beschreibung" aid:cstyle="zei_Produkt_Beschreibung" aid5:cellstyle="zel_Produkt_Beschreibung" aid:theader="">
<xsl:value-of select="TEXT1"/>
</cell>
</xsl:if>
</xsl:for-each>
</Table>
</xsl:template>
</xsl:stylesheet>
失败: 1.行数未正确计算。 2. InDesign不会根据结果构建表格。
有人可以解释问题是什么,并且可能会给我一个正确的代码吗?
答案 0 :(得分:0)
如果我猜对了,你想做这样的事情(省略不相关的属性):
XSLT 1.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>
答案 1 :(得分: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="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”)。
约翰