我需要从XML List-Item转换为Indesign xml代码

西瓦库马尔

我需要从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>

要求的输出

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

需要从XML获取值

绘制形状 - 将 XML 转换为代码

XSL 将简单的 HTML 表格转换为 InDesign 表格(用于 XML 导入)

用于 xml 转换的 XSLT 代码

需要从 XML 中提取元素

需要从XML属性创建HTML表

需要从XML获得特定价值

使用XMLDecoder将编码的XML转换为List <T>

将Spring任务XML配置转换为代码配置

如何阻止Indy将XML中的字符转换为代码

在Python中使用lxml,我需要在输入xml文件中将<RNA>替换为<mark> RNA </ mark>。下面的代码

我在本地 .xml 文件中有一个 xml 响应,我需要在 React 中将其转换为 JSON

我需要帮助将文本文件转换为Java中的xml

使用数组元素将 javascript 对象转换为 xml 为 <item><item>

我想将Excel转换为xml

需要从Hibernate SessionFactory的XML定义引用String JavaBean

XML 转换为 CSV

我需要帮助将C代码转换为MPI

无法从XML节点填充List <Item>

如何使用xslt动态解析xml以检测整数并将其转换为十进制?我在xml文件中也有模式,我需要将其删除

如何使用XMLMapper(Jackson)将List <String []>转换为XML对象?

将XML字符串转换为List <T>而不指定C#中的元素根

如何将List <ExpandoObject>转换为XML字符串

如何将web.xml代码转换为Java旋律的Java配置

无法将下载的代码覆盖率工具转换为XML

Lua:将使用XML dbus定义发出消息的Python代码转换为Lua

如何读取xml文件并将其转换为python代码并运行?

一直在尝试编写将平面xml转换为5级层次结构xml文件的xquery代码

需要将未关闭的元元素 HTML 转换为 XML