2017-01-17 2 views
0
내가 인디자인으로 컨텐츠를 가져 오려면 XSL 코드 내 XML 파일을 변환 할 필요가

를 계산 할 수 없습니다. 불행히도 그룹 중 하나의 하위 노드를 계산하는 데 문제가 있습니다.XML/XSLT는 - 고유의 자식 노드

<?xml version="1.0"?> 
<records> 
    <list> 
     <!-- SPECIAL NOTE --> 
     <specialNote> 
     <specialNoteTitle>Title</specialNoteTitle> 
     <specialNoteContent>Special note content</specialNoteContent> 
     </specialNote> 
     <!-- TITLE & ADDRESS --> 
     <address> 
     <listTitle>December</listTitle> 
     <addressLines> 
      <line1>1</line1> 
      <line2>2</line2> 
      <line3>3</line3> 
      <line4>4</line4> 
     </addressLines> 
     </address> 
     <!-- PRODUCTS --> 
     <products> 
     <productNr1> 
      <productCode>Jeden</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr1> 
     <productNr2> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr2> 
     <productNr3> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr3> 
     <productNr4> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr4> 
     <productNr5> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr5> 
     <productNr6> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr6> 
     <productNr7> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr7> 
     <productNr8> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr8> 
     </products> 
     <!-- CODES --> 
     <promoCodes> 
     <promoCode1> 
      <promoCode>22</promoCode> 
      <instruction>22</instruction> 
     </promoCode1> 
     <promoCode2> 
      <promoCode>21</promoCode> 
      <instruction>23</instruction> 
     </promoCode2> 
     <promoCode3> 
      <promoCode>12</promoCode> 
      <instruction>12</instruction> 
     </promoCode3> 
     <promoCode4> 
      <promoCode>22</promoCode> 
      <instruction>11</instruction> 
     </promoCode4> 
     </promoCodes> 
    </list> 
    <list> 
     <!-- SPECIAL NOTE --> 
     <specialNote> 
     <specialNoteTitle>Title</specialNoteTitle> 
     <specialNoteContent>Special note content</specialNoteContent> 
     </specialNote> 
     <!-- TITLE & ADDRESS --> 
     <address> 
     <listTitle>December</listTitle> 
     <addressLines> 
      <line1>1</line1> 
      <line2>2</line2> 
      <line3>3</line3> 
      <line4>4</line4> 
     </addressLines> 
     </address> 
     <!-- PRODUCTS --> 
     <products> 
     <productNr1> 
      <productCode>Jeden</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr1> 
     <productNr2> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr2> 
     <productNr3> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr3> 
     <productNr4> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr4> 
     <productNr5> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr5> 
     <productNr6> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr6> 
     <productNr7> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr7> 
     <productNr8> 
      <productCode>1</productCode> 
      <productName>1</productName> 
      <productBrand>1</productBrand> 
      <productNK>1</productNK> 
     </productNr8> 
     </products> 
     <!-- CODES --> 
     <promoCodes> 
     <promoCode1> 
      <promoCode>22</promoCode> 
      <instruction>22</instruction> 
     </promoCode1> 
     <promoCode2> 
      <promoCode>21</promoCode> 
      <instruction>23</instruction> 
     </promoCode2> 
     <promoCode3> 
      <promoCode>12</promoCode> 
      <instruction>12</instruction> 
     </promoCode3> 
     <promoCode4> 
      <promoCode>22</promoCode> 
      <instruction>11</instruction> 
     </promoCode4> 
     </promoCodes> 
    </list> 
</records> 

그리고 내 XSL 코드 :

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 

    <!-- MAIN TREE --> 
    <xsl:template match="/"> 
     <records> 
     <xsl:apply-templates/> 
     </records> 
    </xsl:template> 

    <xsl:template match="list"> 
     <list> 
     <xsl:apply-templates select="specialNote"/> 
     <xsl:apply-templates select="address"/> 
     <xsl:apply-templates select="products"/> 
     <xsl:apply-templates select="promoCodes"/> 
     </list> 
    </xsl:template> 

    <!-- SPECIAL NOTE TEMPLATE --> 
    <xsl:template match="specialNote"> 
     <break aid:pstyle="break"> 
     <xsl:if test="*"> 
      <table aid:table="table" aid:trows="2" aid:tcols="1"> 
       <cell aid:table="cell" aid5:cellstyle="special_note_title" aid:crows="1" aid:ccols="1" aid:ccolwidth="362"><xsl:value-of select="specialNoteTitle" /></cell> 
       <cell aid:table="cell" aid5:cellstyle="special_note_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="362"><xsl:value-of select="specialNoteContent" /></cell> 
      </table> 
     </xsl:if> 
     </break> 
     <xsl:text>&#xa;</xsl:text> 
    </xsl:template> 

    <!-- ADDRESS TEMPLATE --> 
    <xsl:template match="address"> 
     <table aid:table="table" aid:trows="4" aid:tcols="2"> 
     <cell aid:table="cell" aid5:cellstyle="address_title" aid:crows="4" aid:ccols="1" aid:ccolwidth="181"><xsl:value-of select="listTitle" /></cell> 
     <xsl:for-each select="addressLines/*"> 
      <cell aid:table="cell" aid5:cellstyle="address_line" aid:crows="1" aid:ccols="1" aid:ccolwidth="181"><xsl:value-of select="." /></cell> 
     </xsl:for-each>  
     </table> 
     <xsl:text>&#xa;</xsl:text> 
    </xsl:template> 

    <!-- PRODUCTS TEMPLATE --> 
    <xsl:template match="products"> 
     <xsl:variable name="products_number" select="count(./*)+1" /> 
     <table aid:table="table" aid:trows="$products_number" aid:tcols="4"> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="61">Code</cell> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="120">Product name</cell> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="120">Product brand</cell> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="61">NK</cell> 
     <xsl:for-each select="*"> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="61"><xsl:value-of select="productCode" /></cell> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="120"><xsl:value-of select="productName" /></cell> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="120"><xsl:value-of select="productBrand" /></cell> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="61"><xsl:value-of select="productNK" /></cell> 
     </xsl:for-each>  
     </table> 
     <xsl:text>&#xa;</xsl:text> 
    </xsl:template> 

    <!-- PROMO CODES TEMPLATE --> 
    <xsl:template match="promoCodes"> 
     <table aid:table="table" aid:trows="5" aid:tcols="2"> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="62">Codes</cell> 
     <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="300">Instruction</cell> 
     <xsl:for-each select="*"> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="62"><xsl:value-of select="promoCode" /></cell> 
      <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="300"><xsl:value-of select="instruction" /></cell> 
     </xsl:for-each> 
     </table> 
     <xsl:text>&#xa;</xsl:text> 
    </xsl:template> 

</xsl:stylesheet> 

문제는 제품 템플릿에서 찾을 수 있습니다 여기에

는 XML 코드입니다. 아시다시피 내 XML 코드는 상당히 복잡합니다. ProductNr1, ProductNr2 등과 같은 고유 한 노드가 많이 있습니다. 불행히도, XML은 Excel에서 내보내지기 때문에 이러한 노드는 하나의 태그 (예 : "제품")로 대체 될 수 없습니다 (필자의 경우 열당 고유 한 태그가 필요합니다). InDesign의 테이블을 작성하려면 해당 행 ("products"의 모든 하위 항목 +1)을 계산해야합니다. 내 XPATH가이를 수행해야하지만 InDesign을 사용하면 InDesign에서 XML 가져 오기를 거부합니다. 제품 테이블의 계산 된 행 수가 올바르지 않기 때문에이 가정합니다.

내가 뭘 잘못하고 있니?

+3

당신은 출력 XML은 대상 응용 프로그램에 의해 접수하기 위해 같이 할 필요가 뭔지 알아? 그렇다면 질문을 편집하고 예상 결과를 추가하십시오. –

+0

지금은 고유 한 노드가 아니라 노드를 포함합니다. 그리고'$ products_number'가 평가 된 값 대신 렌더링을한다는 것에 문제가 있습니까? – Parfait

+0

@ Parfait : 예, 문제는'$ products_number' 값에 있습니다. 변수 대신 숫자로 코드를 테스트 해 보았습니다. 내 테이블에는 최대 50 개의 행이 있으므로 노드 수를 계산해야합니다./ – yarek

답변

0

나는 하나의 문제를 볼 수 있지만, 나는 당신의 예상 XML이 어떻게 생겼는지 모르기 때문에 문제를 일으키는 유일한하지 않을 수 있습니다. 그러나, 문제는 실제로 당신이 변수 $products_number을 평가하고, 변수의 결과를 사용할 때, 테이블

aid:trows="$products_number" 

이것은 말 그대로 출력이 입력 한 무슨의 trows 속성을 설정하는 방법에있다. 는 XML 출력 인 경우이 작업을 수행하려면, Attribute Value Templates

aid:trows="{$products_number}" 

를 사용, 그 다음에 예를 들어, aid:trows="9"로 출력을해야합니다.

0

팀 C 나보다 더 빨리했지만, 난 같은 말을하고 있었다.

또한, 당신이 어떤 아이 이름이()에보고하여 "제품"검색을 구체화 할 수 있습니다로 시작 'productNr'

내가 설명은 제품에 대한 XSL 템플릿을 게시하고있다 :

<!-- PRODUCTS TEMPLATE --> 
 
    <xsl:template match="products"> 
 
     <xsl:variable name="products" select="./*[starts-with(name(), 'productNr')]"/> 
 
     <xsl:variable name="products_number" select="count($products)+1" /> 
 
     <table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" aid:trows="{$products_number}" aid:tcols="4"> 
 
      <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="61">Code</cell> 
 
      <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="120">Product name</cell> 
 
      <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="120">Product brand</cell> 
 
      <cell aid:table="cell" aid5:cellstyle="table_head" aid:crows="1" aid:ccols="1" aid:ccolwidth="61">NK</cell> 
 
      <xsl:for-each select="$products"> 
 
       <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="61"><xsl:value-of select="productCode" /></cell> 
 
       <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="120"><xsl:value-of select="productName" /></cell> 
 
       <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="120"><xsl:value-of select="productBrand" /></cell> 
 
       <cell aid:table="cell" aid5:cellstyle="table_content" aid:crows="1" aid:ccols="1" aid:ccolwidth="61"><xsl:value-of select="productNK" /></cell> 
 
      </xsl:for-each>  
 
     </table> 
 
     <xsl:text>&#xa;</xsl:text> 
 
    </xsl:template>