Answered by:
MSBuild 4 XslTransformation Task - how to pass parameter
Question
-
Just getting some stuff ported to MSBuild4 and needing to pass xsl:param to a stylesheet. I see that the Parameters attribute is a string but not sure how to use it? I have two parameters.
Tuesday, October 19, 2010 3:25 PM
Answers
-
Thanks for your reply Ziwei. My question was actually how to pass a parameter to an xslt transformation. I just found the solution. Given a parameter (xsl:param) named 'rootPath' in my stylesheet:
<XslTransformation XslInputPath="preprocessAndFilter.xslt" XmlInputPaths="$(ChangesFileName)" OutputPaths="out_preprocessAndFilter.xml" Parameters="<Parameter Name='rootPath' Value='$(RootPath)'/>"/>
I found a tool called Reflector that could reflect on the msbuild tasks dll and saw that the code takes the string value in that attribute and concatenates and beginning and an ending xml tag to create an xml dom where the <Parameter> elements can be iterated.
Kelly- Marked as answer by kellycole6 Wednesday, October 20, 2010 2:09 PM
Wednesday, October 20, 2010 2:09 PM
All replies
-
Thanks for your post.
As far as I know, both xsl:variable and xsl:param are allowed as top-level elements. A top-level variable-binding element declares a global variable that is visible everywhere. A top-level xsl:param element declares a parameter to the stylesheet; XSLT does not define the mechanism by which parameters are passed to the stylesheet. It is an error if a stylesheet contains more than one binding of a top-level variable with the same name and same import precedence.
For more information, please check:
And here is an example from MSDN Library:
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="paramelem.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="ol/li">
<br/>
<xsl:call-template name="numbered-block"/>
</xsl:template>
<xsl:template match="ol//ol/li">
<br/>   
<xsl:call-template name="numbered-block">
<xsl:with-param name="format">a. </xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="numbered-block">
<xsl:param name="format">1. </xsl:param>
<fo:block>
<xsl:number format="{$format}"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
</xsl:stylesheet>Ziwei Chen
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.comWednesday, October 20, 2010 3:24 AM -
Thanks for your reply Ziwei. My question was actually how to pass a parameter to an xslt transformation. I just found the solution. Given a parameter (xsl:param) named 'rootPath' in my stylesheet:
<XslTransformation XslInputPath="preprocessAndFilter.xslt" XmlInputPaths="$(ChangesFileName)" OutputPaths="out_preprocessAndFilter.xml" Parameters="<Parameter Name='rootPath' Value='$(RootPath)'/>"/>
I found a tool called Reflector that could reflect on the msbuild tasks dll and saw that the code takes the string value in that attribute and concatenates and beginning and an ending xml tag to create an xml dom where the <Parameter> elements can be iterated.
Kelly- Marked as answer by kellycole6 Wednesday, October 20, 2010 2:09 PM
Wednesday, October 20, 2010 2:09 PM -
Hi Kelly,
Glad to know it is resolved.
Ziwei Chen
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.comThursday, October 21, 2010 1:58 AM