【问题标题】:ANT ANTForm XSL - Cheat SheetANT ANTForm XSL - 备忘单
【发布时间】:2010-09-02 14:16:15
【问题描述】:

另一个问题-Getting directory listing from SVN for use in ANT dropdown

我询问了如何将 SVN 直接连接到我的 ANT 脚本。我得到的答案非常好,遵循从 SVN 将目录列表导出为 XML,然后使用 XSL 构建表单。

我没有使用 XSL 的经验,所以我想知道是否有人可以给我任何指示?更具体地说,通过 XSL 在 ANTForms 中构建表单。他们的网站似乎没有提到任何关于使用它的内容,我在 Google 上找不到任何东西。

其他信息...

这是我从 SVN 返回的 XML 的一个小示例。

<?xml version="1.0"?>
<lists>
<list path="https://example.com/svn/website/tags">
    <entry kind="dir">
        <name>archive</name>
        <commit revision="1337">
            <author>itncj</author>
            <date>2010-02-17T12:21:22.342500Z</date>
        </commit>
    </entry>
    <entry kind="dir">
        <name>milestone 1-0-0</name>
        <commit revision="1302">
            <author>jcb4337</author>
            <date>2010-02-12T10:15:00.282625Z</date>
        </commit>
    </entry>
    <entry kind="dir">
        <name>milestone 1-0-0b</name>
        <commit revision="1329">
            <author>itncj</author>
            <date>2010-02-17T12:08:56.248750Z</date>
        </commit>
    </entry>
</list>

我需要的只是名称节点,因此我可以构建以下结构的形式 -

  • 一些标题标签
  • 标签 |文本字段
  • 下拉列表中的 SVN CALL1 名称
  • 下拉列表中的 SVN CALL2 名称
  • 下拉列表中的 SVN CALL3 名称
  • YES / NO
  • 下拉列表中的 SVN CALL4 名称
  • 测试/生产 />
  • 密码文本字段
  • 部署按钮
  • 取消按钮

希望这是有道理的,但我需要做的是进行 x4 SVN 调用,每个存储库都保存我们的项目文件(主项目文件、相关组件、插件和核心)并使用 ANTForm 的 selectionProperty 填充这些下拉列表(http://antforms.sourceforge.net/usageaf.html)。

除此之外,我还需要做更多的事情(比如在每个下拉列表的开头附加“Trunk”),但一次一步。

【问题讨论】:

  • XSLT 是一种将任何 XML 文档转换为另一个文档的技术。我建议从这里开始:w3schools.com/xsl
  • 我不是 XML SVN 和 ANTForms 专家,但如果您要提供减少输入样本和所需输出,有人会帮助您。
  • @Mark - 抱歉,这可能只是我的术语,但这个术语与您上次有用的回复无关 :-)。你给我的示例代码工作得很好,但我想看看我能用它做多远,即用选项填充下拉列表等。@Alejandro - 感谢您的建议。明天早上我会在这里举个例子。
  • 我想我可能有一个额外的复杂性,因为我对 XML 文件进行单独调用,然后想在下拉列表中使用它们。我想我需要先将所有这些 XML 文件合并在一起,或者有没有办法可以调用单独的 XML 文件以与一个 XSLT 一起使用?我猜不是:-(

标签: xslt ant


【解决方案1】:

我过去使用的一种策略是让 ANT 脚本生成另一个 ANT 构建文件,然后在运行中执行该动态生成的 ANT 构建文件:

  1. 调用进程(获取 SVN 信息)
  2. 调用 XSLT 以动态生成另一个 ANT 构建文件(使用动态构造的 ANTForm)
  3. 调用动态生成的 ANT 构建文件(使用 antcall、ant 等)

这样的样式表可以用作生成动态 ANT 构建文件的起点,该文件调用动态生成的 ANT 表单:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>

    <xsl:template match="/">
        <project name="enhancedRSS" default="form" basedir=".">
            <taskdef name="antform" classname="com.sardak.antform.AntForm" 
                classpath="${antform.home}/lib/antform.jar"/>
            <target name="form">
                <xsl:call-template name="ANTFORM" />
            </target>
        </project>
    </xsl:template>

    <xsl:template name="ANTFORM">
        <antform title="Example ANTForm generated from XSLT">

            <label>Some title label</label>
            <textProperty label="LABEL" property="label1" required="true" focus="true"
                tooltip="This is the first label, which will assign the value entered to the ANT property label1" />

            <selectionProperty label="Values from SVN-CALL1:" property="svn-call1" separator=";">
                <xsl:attribute name="values">
                    <xsl:call-template name="SVN-CALL1" />
                </xsl:attribute>
            </selectionProperty>

            <selectionProperty label="Values from SVN-CALL2:" property="svn-call2" separator=";">
                <xsl:attribute name="values">
                    <xsl:call-template name="SVN-CALL2" />
                </xsl:attribute>
            </selectionProperty>

            <selectionProperty label="Values from SVN-CALL3:" property="svn-call3" separator=";">
                <xsl:attribute name="values">
                    <xsl:call-template name="SVN-CALL3" />
                </xsl:attribute>
            </selectionProperty>

            <radioSelectionProperty label="Release core files: " property="release" values="Yes;No" separator=";" />

            <selectionProperty label="Which verion of the core:">
                <xsl:attribute name="values">
                    <xsl:call-template name="SVN-CALL4" />
                </xsl:attribute>
            </selectionProperty>

            <radioSelectionProperty label="Environment: " property="environment" values="Test;Production" separator=";" />

            <textProperty label="Password" property="svn.password" required="true" password="true" />

            <controlbar>
                <button label="Cancel" type="cancel" />
                <button label="Deploy" target="deploy" />
            </controlbar>
        </antform>
    </xsl:template>

    <xsl:template name="SVN-CALL1">
       <xsl:text>Trunk</xsl:text> 
        <xsl:for-each select="/lists/list/entry/name">
            <xsl:text>;</xsl:text>
            <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="SVN-CALL2">
        <!--Similar logic as SVN-CALL1-->
    </xsl:template>
    <xsl:template name="SVN-CALL3">
        <!--Similar logic as SVN-CALL1-->
    </xsl:template>
    <xsl:template name="SVN-CALL4">
        <!--Similar logic as SVN-CALL1-->
    </xsl:template>
</xsl:stylesheet>

它使用您描述的大部分 ANT 表单创建此 ANT 构建文件(应该足以让您开始使用):

<?xml version="1.0" encoding="UTF-8"?>
<project name="enhancedRSS" default="form" basedir=".">
   <taskdef name="antform" classname="com.sardak.antform.AntForm"
            classpath="$/lib/antform.jar"/>
   <target name="form">
      <antform title="Example ANTForm generated from XSLT">
         <label>Some title label</label>
         <textProperty label="LABEL" property="label1" required="true" focus="true"
                       tooltip="This is the first label, which will assign the value entered to the ANT property label1"/>
         <selectionProperty label="Values from SVN-CALL1:" property="svn-call1" separator=";"
                            values="Trunk;archive;milestone 1-0-0;milestone 1-0-0b"/>
         <selectionProperty label="Values from SVN-CALL2:" property="svn-call2" separator=";" values=""/>
         <selectionProperty label="Values from SVN-CALL3:" property="svn-call3" separator=";" values=""/>
         <radioSelectionProperty label="Release core files: " property="release" values="Yes;No" separator=";"/>
         <selectionProperty label="Which verion of the core:" property="svn-call4" values=""/>
         <radioSelectionProperty label="Environment: " property="environment" values="Test;Production"
                                 separator=";"/>
         <textProperty label="Password" property="svn.password" required="true" password="true"/>
         <controlbar>
            <button label="Cancel" type="cancel"/>
            <button label="Deploy" target="deploy"/>
         </controlbar>
      </antform>
   </target>
</project>

执行时,生成的 ANT 构建文件和 ANT Form 生成:

这应该足以让您入门。 ANTForm usage page 告诉您每个 ANTForm 元素的每个属性是什么。您还可以进行更多自定义操作(使用自己的 CSS、自定义图标、保存属性以在下次运行时预填充表单等)

如果您要将四个 SVN 调用的结果保存在单独的 XML 文件中,那么您可能需要考虑使用 XSLT document() 函数在单个 XSLT 中完成您需要的工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-29
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2015-08-07
    • 1970-01-01
    相关资源
    最近更新 更多