2014-02-19 3 views
1

XML에서 Indesign XML 코드로 변환해야합니다. 친절하게 조언 누군가가 대답을 알아.XML 목록 항목에서 Indesign XML 코드로 변환해야합니다.

<root> 
<p><list list-type="order"> 
<list-item><p>This is quick.</p></list-item> 
<list-item><p>Sivakumar Given and the fact that 
    <list list-type="bullet"> 
    <list-item><p>This is sublist</p></list-item> 
    <list-item><p>This is sub middle list</p></list-item> 
    <list-item><p>This is sub last list</p></list-item> 
    </list> 
</p></list-item> 
<list-item><p>We are now left with four remaining parameters:</p></list-item> 
<list-item><p>Given and the fact that</p></list-item> 
<list-item><p>In Section we obtained an estimate for the mean of.</p></list-item> 
<list-item><p>From steps 3, 4, and 5 above, we have generated (a table of) values for.</p></list-item> 
</list></p> 
</root> 

필수 출력

<root> 
<p><list list-type="order"> 
<list-item aid:pstyle="Order-First"><p>This is quick.</p></list-item> 
<list-item aid:pstyle="Order-Middle"><p>Sivakumar Given and the fact that 
    <list list-type="bullet"> 
    <list-item aid:pstyle="SubBullet-First"><p>This is sublist</p></list-item> 
    <list-item aid:pstyle="SubBullet-Middle"><p>This is sub middle list</p></list-item> 
    <list-item aid:pstyle="SubBullet-Last"><p>This is sub last list</p></list-item> 
    </list> 
</p></list-item> 
<list-item aid:pstyle="Order-Middle"><p>We are now left with four remaining parameters:</p></list-item> 
<list-item aid:pstyle="Order-Middle"><p>Given and the fact that</p></list-item> 
<list-item aid:pstyle="Order-Middle"><p>In Section we obtained an estimate for the mean of.</p></list-item> 
<list-item aid:pstyle="Order-Last"><p>From steps 3, 4, and 5 above, we have generated (a table of) values for.</p></list-item> 
</list></p> 

감사 시바 쿠마 M.

+0

내 대답은 XSLT 될 것이다. 또는 XQuery. XML을 파싱/조작/직렬화하기 위해 표준 API를 사용하여 손으로 작성한 코드. 그러나 귀하의 제안 된 출력은 고장났습니다; 현대 XML 도구가 문서를 받아들이게하려면'aid :'접두어에 대한 네임 스페이스 바인딩을 제공해야합니다. – keshlam

답변

1

입력 XML이 스타일 시트를 사용할 수 있습니다. 해당 버전의 네임 스페이스 xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0"이 올바른지 확인하십시오.

<?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"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="list-item[../@list-type='order']"> 
     <xsl:copy> 
      <xsl:call-template name="add-attribute-to-list-item"> 
       <xsl:with-param name="type" select="'Order'"/> 
      </xsl:call-template> 
      <xsl:apply-templates /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="list-item[../@list-type='bullet']"> 
     <xsl:copy> 
      <xsl:call-template name="add-attribute-to-list-item"> 
       <xsl:with-param name="type" select="'SubBullet'"/> 
      </xsl:call-template> 
      <xsl:apply-templates /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template name="add-attribute-to-list-item"> 
     <xsl:param name="type"/> 
      <xsl:attribute name="aid:pstyle"> 
       <xsl:choose> 
        <xsl:when test="position() = 1"> 
         <xsl:value-of select="concat($type,'-First')"/> 
        </xsl:when> 
        <xsl:when test="position() = last()"> 
         <xsl:value-of select="concat($type,'-Last')"/> 
        </xsl:when> 
        <xsl:otherwise> 
         <xsl:value-of select="concat($type,'-Middle')"/> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:attribute> 
    </xsl:template> 

    <xsl:template match="*"> 
     <xsl:copy> 
      <xsl:copy-of select="@*"/> 
      <xsl:apply-templates/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/"> 
     <root><xsl:apply-templates select="root/p"/></root> 
    </xsl:template> 

</xsl:stylesheet> 

결과는 다음과 같습니다

<?xml version="1.0" encoding="UTF-8"?> 
<root xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0"> 
    <p> 
     <list list-type="order"> 
     <list-item aid:pstyle="Order-First"> 
      <p>This is quick.</p> 
     </list-item> 
     <list-item aid:pstyle="Order-Middle"> 
      <p>Sivakumar Given and the fact that 
      <list list-type="bullet"> 
        <list-item aid:pstyle="SubBullet-First"> 
        <p>This is sublist</p> 
        </list-item> 
        <list-item aid:pstyle="SubBullet-Middle"> 
        <p>This is sub middle list</p> 
        </list-item> 
        <list-item aid:pstyle="SubBullet-Last"> 
        <p>This is sub last list</p> 
        </list-item> 
       </list> 
      </p> 
     </list-item> 
     <list-item aid:pstyle="Order-Middle"> 
      <p>We are now left with four remaining parameters:</p> 
     </list-item> 
     <list-item aid:pstyle="Order-Middle"> 
      <p>Given and the fact that</p> 
     </list-item> 
     <list-item aid:pstyle="Order-Middle"> 
      <p>In Section we obtained an estimate for the mean of.</p> 
     </list-item> 
     <list-item aid:pstyle="Order-Last"> 
      <p>From steps 3, 4, and 5 above, we have generated (a table of) values for.</p> 
     </list-item> 
     </list> 
    </p> 
</root> 
+0

안녕하세요, 귀하의 답변이 잘 작동하고 정말 고마워요! –

+0

@SivakumarM이 답변을 수락하십시오 (왼쪽의 체크 표시가 녹색으로 표시). 그것은 "감사합니다"라고 말하는 정중 한 방법입니다. –

관련 문제