On Friday, May 3, 2002, at 01:01 PM, Diane Holt wrote:
> --- Scott Ellsworth <[EMAIL PROTECTED]> wrote:
>> I cannot figure out how to make xslt give me
>>
>> <target name="build-thing" depends="build-subthing1, build-subthing2">
>> -- other stuff
>> </target>
>
> I could be wrong (have so far only glanced through my free XSLT
> book :), but could you use the concat() function?
This is pretty close to what I ended up doing.
For the curious:
<xsl:template name="make-name-attribute-list">
<!-- Turns the $elements list into a comma separated string with
$prefix prepended and $postfix appended to each element. -->
<xsl:param name="elements"/>
<xsl:param name="prefix"/>
<xsl:param name="postfix"/>
<xsl:for-each select="$elements">
<xsl:value-of select="concat($prefix,@name,$postfix)" />
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="concat-with-comma">
<!-- If either first or second is not null, return the two seperated
by a comma. -->
<xsl:param name="first"/>
<xsl:param name="second"/>
<xsl:choose>
<xsl:when test="not(boolean(normalize-
space(string($first))))"><xsl:value-of select="$second" /></xsl:when>
<xsl:when test="not(boolean(normalize-
space(string($second))))"><xsl:value-of select="$first" /></xsl:when>
<xsl:otherwise><xsl:value-of select="concat($first,', ',$second)"
/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:for-each select="project">
<xsl:choose>
<xsl:when test="normalize-space(@build)!='false'">
<xsl:variable name="build-depend-list">
<xsl:call-template name="make-name-attribute-list">
<xsl:with-param name="elements"
select="depend[@type='project']" />
<xsl:with-param name="prefix" select="'build-'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="build-depend-list-with-init">
<xsl:call-template name="concat-with-comma">
<xsl:with-param name="first" select="'init'" />
<xsl:with-param name="second"
select="$build-depend-list" />
</xsl:call-template>
</xsl:variable>
<target name="build-{@name}"
depends="{$build-depend-list-with-init}" description="Build {@name}">
<echo message="Building {@name} without dependencies"/>
<ant dir="{@directory}" target="${{build.buildcommand}}"
output="${{build.log}}/{@name}"/>
</target>
</xsl:when>
</xsl:choose>
</xsl:for-each>
This works great.
I am now trying to make a build-all variable that will have all depends
with @type='project' that are part of projects with build!= 'false', but
I am having some problems. I do not understand why
<xsl:with-param name="elements"
select="project[@build!='false']/depend[@type='project']" />
does not give me the list of depends that I want.
Scott
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>