You are mixing concepts... Although your XSLT is invoked from Ant, you
lose Ant's properties. Quite honestly, this is no different than kicking
off an XSLT from a Java app...the XSLT is somewhat insulated :)
You will need to use the param subelement... This should fix your problem
(although I have not tested):
Ant:
<property name="floorType" value="wood"/>
<xslt basedir="${workDir}" extension=".xml"
destdir="out/"style="style/setValues.xsl">
<include name="**/*.xml"/>
<param name="floorType" expression="${floorType}"/>
</xslt>
XSLT:
<xsl:param name="floorType"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="floor[../tapestry='red']">
<floor>$floorType</floor>
</xsl:template>
Just put the <xsl:param> line up close to the top of your transform
(although I don't think it has to exactly be there)...
Note, using $floorType in the XSLT as opposed to ${floorType} - in XSLT
you don't wrap variables/param within curly braces...
If this is still wrong, within Ant's XSLT param, you may have to do this:
<xslt basedir="${workDir}" extension=".xml"
destdir="out/"style="style/setValues.xsl">
<include name="**/*.xml"/>
<param name="floorType" expression="'${floorType}'"/>
</xslt>
See the single ticks around ${floorType}?
Honestly, its been a while since I passed in params from an Ant
script...one of the two should work...
HTH,
Flossy
On Fri, 17 Dec 2010, Jo Support wrote:
Hello people,
how do I pass a variable to a stylesheet using xslt task?
I have this ant script:
<property name="floorType" value="wood"/>
<xslt basedir="${workDir}" extension=".xml" destdir="out/"
style="style/setValues.xsl">
<include name="**/*.xml"/>
</xslt>
and this stylesheet:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="floor[../tapestry='red']">
<floor>${floorType}</floor>
</xsl:template>
but the process writes in the output file exactly
<floor>${floorType}</floor>
instead of the value of the property.
Where am I doing wrong?
Thanks a lot
Jo
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org
--
Scot P. Floess
RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
Chief Architect Keros http://sourceforge.net/projects/keros
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org