Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要从XML列表项转换为Indesign XML代码_Xml_Xslt_Adobe Indesign - Fatal编程技术网

我需要从XML列表项转换为Indesign XML代码

我需要从XML列表项转换为Indesign XML代码,xml,xslt,adobe-indesign,Xml,Xslt,Adobe Indesign,我需要从XML转换为Indesign XML代码。请告诉任何知道答案的人 输入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="bu

我需要从XML转换为Indesign XML代码。请告诉任何知道答案的人

输入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>


这很快

Sivakumar给出了 这是子列表

这是次中间列表

这是最后一张名单

现在剩下四个参数:

鉴于

在第节中,我们得到了平均值的估计值

从上面的步骤3、4和5中,我们已经生成了的(一个表)值

所需输出

<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>


这很快

Sivakumar给出了 这是子列表

这是次中间列表

这是最后一张名单

现在剩下四个参数:

鉴于

在第节中,我们得到了平均值的估计值

从上面的步骤3、4和5中,我们已经生成了的(一个表)值

谢谢
Sivakumar M.

您可以使用此样式表。检查名称空间是否
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>


这很快

Sivakumar给出了 这是子列表

这是次中间列表

这是最后一张名单

现在剩下四个参数:

鉴于

在第节中,我们得到了平均值的估计值

从上面的步骤3、4和5中,我们已经生成了的(一个表)值


我的答案是XSLT。或者XQuery。或者使用标准API手工编写代码来解析/操作/序列化XML。但是:您提议的输出被破坏;如果希望文档被现代XML工具接受,必须为
aid:
前缀提供名称空间绑定。您好,您的答案很好,非常感谢@SivakumarM请接受此答案(在左侧标记勾号,使其显示为绿色)。这是对Stackoverflow说“谢谢”的礼貌方式。