NANT: Style task passing parameter to xslt
I have a problem with passing arguments from the NAnt style task to a xslt sheet. This is my NAnt code snippet. The properties path and file are definetly set.
<style style="${xslt.file}" extension="xml" in="${xml.file}" destdir=".">
<parameters>
<parameter name="path" value="${path}"
namespaceuri="http://www.w3.org/1999/XSL/Transform" />
<parameter name="doc" value="${file}"
namespaceuri="http://www.w3.org/1999/XSL/Transform" />
</parameters>
</style>
My Parameter are declared as following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="http://schemas.microsoft.com/developer/msbuild/2003">
<xsl:param name="path"></xsl:param>
<xsl:param name="file" />
And accessed by:
<xsl:value-of select="$path" />
<xsl:value-of select="$file" />
But when the file is transformed, $path and $file are both empty. I have tried with and w开发者_JAVA技巧ithout the namespaceuri of the style task.
What I am doing wrong?Thanking you in anticipation.
Hmmm, why do you set $file and use $doc ?
BTW, here is a working example:
<style style="web.config.xsl" in="web.config.xsl" out="web.config">
<parameters>
<parameter name="OSVersion" value="${OSVersion}"/>
</parameters>
</style>
and the XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="OSVersion"/>
<xsl:template match="/">
<xsl:value-of select="$OSVersion"/>
</xsl:template>
</xsl:stylesheet>
I just encountered the phenomenon Dennis described in his comment on the first answer. It seems that NAnt only executes the XSLT again if it has changed and doesn't notice that you have changed the parameters for the <style>
element. Hence, once you have added your <parameter>
elements to your NAnt file, running NAnt will not cause the XSLT to run with the new parameter values unless you have changed the XSLT file itself.
精彩评论