xslt 1.0-选择选项不起作用



我的构建脚本创建了4个不同的build 名称

STP_13_00_00_00_RC01
STPMON_13_00_00_00_RC01
STPWEB_13_00_00_00_RC01
STPPRODUCTS_13_00_00_00_RC01

所以我希望当脚本创建名为**STP_13_00_00_00_RC01**的构建时,它应该创建文件夹,然后将tar文件复制到该文件夹中,然后再创建一个文件夹,而如果构建名称以其他名称STPMON、STPWEB.STPPRODUCTS开头,那么它应该只创建文件夹,并将tar文件拷贝到该文件夹。所以我使用了以下条件。但对于所有构建,它都会进入其他状态,要么使用STP 创建构建

</xsl:element>
<xsl:element name="gzip">
  <xsl:attribute name="destfile"
    >${archive.base}/${gbl.dist.label}.tar.gz</xsl:attribute>
  <xsl:attribute name="src"
    >${archive.base}/${gbl.dist.label}.tar</xsl:attribute>
</xsl:element>
<xsl:choose>
  <xsl:when test="contains(node,'STP')">
    <xsl:element name="mkdir">
      <xsl:attribute name="dir"
        >/mnt/projects/autoblds_dev_build/blds_dev_stp2build/${gbl.dist.label}</xsl:attribute>
    </xsl:element>
    <xsl:element name="copy">
      <xsl:attribute name="file">${archive.base}/${gbl.dist.label}.tar.gz</xsl:attribute>
      <xsl:attribute name="todir"
        >/mnt/projects/autoblds_dev_build/blds_dev_stp2build/${gbl.dist.label}/</xsl:attribute>
      <xsl:attribute name="overwrite">no</xsl:attribute>
    </xsl:element>
    <xsl:element name="mkdir">
      <xsl:attribute name="dir"
        >/mnt/projects/autoblds_dev_build/blds_dev_stp2build/${soa.release.version}</xsl:attribute>
    </xsl:element>
  </xsl:when>
  <xsl:otherwise>
    <xsl:element name="mkdir">
      <xsl:attribute name="dir"
        >/mnt/projects/autoblds_dev_build/blds_dev_stp2build/${gbl.dist.label}_Test</xsl:attribute>
    </xsl:element>
    <xsl:element name="copy">
      <xsl:attribute name="file"
         >${archive.base}/${gbl.dist.label}.tar.gz</xsl:attribute>
      <xsl:attribute name="todir"
         >/mnt/projects/autoblds_dev_build/blds_dev_stp2build/${gbl.dist.label}_Test/</xsl:attribute>
      <xsl:attribute name="overwrite">no</xsl:attribute>
    </xsl:element>
  </xsl:otherwise>
</xsl:choose>

您选择的指令在条件上分支

contains(node,'STP')

这至少有一个问题,可能还有两个问题。

您对问题的描述表明,对于名为STP_13_00_00_00_RC01的构建,您希望以一种方式行事,而对于名称以STPMONSTPWEBSTPPRODUCTS开头的构建,则希望以不同的方式行事。但是所有这些构建名称都包含字符串"STP",所以您的测试条件无法区分它们。换句话说,你的代码不会做你想做的事情,因为你没有说出你的意思。

您说测试永远不会成功(样式表总是采用otherwise分支)。这表明表达式node的计算结果不是您所期望的字符串,也不是可能被强制为您所期望字符串的文档节点。可能的原因包括:

  • 您的XML没有名为node的元素
  • XML有一个名为node的元素,但它不是引用代码的模板的上下文节点的子节点
  • XML有一个名为node的元素,它是上下文节点的子节点,但它的字符串值不是构建的名称

这些都有可能,但如果非要我猜的话,我猜这是第一个。

最新更新