我無法將XML項目列表轉換爲獨立表格。一個問題是計算行數,因爲這是必需的,但不能作爲簡單的count()處理。使用XSLT將動態XML轉換爲Adobe InDesign表
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是空的。在這種情況下:這個項目沒有第二行。
Therfore我寫下這個(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不會根據結果生成表格。
有人可以解釋有什麼問題,也許給我一個正確的代碼?
您可以發佈轉換的預期XML結果嗎? –