unknown
unknown

Reputation: 1893

if condition in xsl

I need to put if condition like the format of my build is something like that STP_13_00_00_00_RC01 or STPMON_13_00_00_00_RC01.If perfix is STP then I want to run a small script and if perfix other that STP no need to run script and use other action.How could I achieve this?

I mada some changes in my code what I am doing here is create the folder and copy the tar file to that folder.Here the folder name start with STP or ACH then I want to execute my script with some parameters else nothing.

   <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:choose>
            <xsl:when test="starts-with(Node, 'STP')">
            <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>
            <!-- alternative action -->
            </xsl:otherwise>
            </xsl:choose>

Upvotes: 0

Views: 702

Answers (2)

Treemonkey
Treemonkey

Reputation: 2163

<xsl:choose>
  <xsl:when test="contains(node,"STP")">
    <!-- action -->
  </xsl:when>
  <xsl:otherwise>
    <!-- alternative action -->
  </xsl:otherwise>
</xsl:choose>

Upvotes: 0

JLRishe
JLRishe

Reputation: 101652

Your XSLT says "condition one or condition two", but I only see one condition in your question. To test whether a value has a certain prefix, you can do this:

<xsl:choose>
  <xsl:when test="starts-with(Node, 'STP')">
    <!-- action -->
  </xsl:when>
  <xsl:otherwise>
    <!-- alternative action -->
  </xsl:otherwise>
</xsl:choose>

Upvotes: 1

Related Questions