Transform Task
Transforms XML inputs by using an Extensible Stylesheet Language Transformation (XSLT) program and outputs to one or more files.
Parameters
The following table describes the parameters of the Transform task.
Parameter | Description |
---|---|
CollectionsCollectionsCollections |
Optional ITaskItemITaskItemITaskItem[] parameter. Specifies the available collections. If the CollectionURI metadata is defined the item will be added to the specified collection. Otherwise the items will be set as the default collection. |
InitialModeInitialModeInitialMode |
Optional stringStringString parameter. Specifies the initial template mode to apply when executing the transformation. This parameter is in Clark notation. "{URI}local" represents the local name "local" in the namespace "URI", or "local" if no namespace is required. |
InitialTemplateInitialTemplateInitialTemplate |
Optional stringStringString parameter. Specifies the initial template to call when executing the transformation. This parameter is in Clark notation. "{URI}local" represents the local name "local" in the namespace "URI", or "local" if no namespace is required. |
InputInputInput |
Optional ITaskItemITaskItemITaskItem parameter. Specifies the path of an XML input file to use as the context item. |
OptimizationLevelOptimizationLevelOptimizationLevel |
Optional intIntegerint parameter. Specifies the compilation optimization level. The default value is 3. If the value is less than zero or greater than 4, the default optimization level is used. |
OutputOutputOutput |
Required ITaskItemITaskItemITaskItem parameter. Specifies the principal output file from executing the transformation. |
OutputFilesOutputFilesOutputFiles |
Optional ITaskItemITaskItemITaskItem[] output parameter. Receives the result documents created by the transformation. MediaType and Encoding custom metadata contain the mime-type and character encoding of each output. |
ParametersParametersParameters |
Optional stringStringString parameter. Specifies the values of stylesheet parameters. The value of this parameter should be set to a series of XML elements of the following form: <Parameter Name="..." [Namespace="..."] [Value="..."] [Select="..."] />
The |
ProcessXsiSchemaLocationProcessXsiSchemaLocationProcessXsiSchemaLocation |
Optional boolBooleanbool parameter.
Specifies whether |
SchemasSchemasSchemas |
Optional ITaskItemITaskItemITaskItem[] parameter. Specifies the set of XML Schema files used for validation. |
SerializationParametersSerializationParametersSerializationParameters |
Optional stringStringString parameter. Specifies the values of serialization parameters. The value of this parameter should be set to a series of XML elements of the following form: <Parameter Name="..." [Namespace="..."] Value="..." />
The |
SerializationParameterDocumentSerializationParameterDocumentSerializationParameterDocument |
Optional ITaskItemITaskItemITaskItem parameter. Specifies a serialization parameter document from which to read serialization parameters. |
StripWhitespaceStripWhitespaceStripWhitespace |
Optional boolBooleanbool parameter.
Specifies whether the whitespace will be stripped from source documents.
If not specified, the default value is |
ValidationValidationValidation |
Optional stringStringString parameter.
Specifies whether the source documents will be validated using a DTD ("dtd"), XML Schemas ("schema") or no validation will be performed ("none").
If not specified, the default value is |
XslXslXsl |
Required ITaskItemITaskItemITaskItem parameter. Specifies the path of the XSL transformation. |
Remarks
Parameters and serialization parameters are passed as XML "Parameter" tags with Name, NamespaceURI and Value attributes. The Value attribute must be an XPath expression. See the example below for details.
If both InitialMode and InitialTemplate are specified, the task fails and an error is logged.
In addition to having the parameters that are listed in the table, this task inherits parameters from the TaskTaskTask class. For a list of these additional parameters and their descriptions, see Task Base Class.
Example
The following example transforms input document document.xml to output.htm using the transformation stylesheet.xsl. Values are supplied for stylesheet parameters 'data' (in namespace 'http://www.example.org/) 'name', 'size' and 'date' are defined. The 'method' serialization parameter is set to XHTML. Input documents are validated using XML Schema against a set of files with extension 'xsd'. The initial template mode is specified as 'classic' in the 'http://www.example.org/' namespace. Two collections are made available with URIs 'urn:foo' and 'urn:bar'.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath32)\XmlPrime.Tasks\XmlPrime.Tasks.Tasks"/> <ItemGroup> <Stylesheet Include="stylesheet.xsl" /> <ContextDocument Include="document.xml" /> <Schemas Include="*.xsd" /> <FooCollection Include="foo*.xml"> <CollectionURI>urn:foo</CollectionURI> </FooCollection> <BarCollection Include="bar*.xml"> <CollectionURI>urn:bar</CollectionURI> </BarCollection> </ItemGroup> <PropertyGroup> <SerializationParameters> <!-- set the serialization method to XHTML --> <Parameter Name="method" Value="xhtml" /> </SerializationParameters> <StylesheetParameters> <!-- bind parameter 'name' to the string 'Jethro' --> <Parameter Name="name" Value="Jethro" /> <!-- bind parameter 'data' in namespace 'http://www.example.org/' to the document data.xml --> <Parameter Name="data" NamespaceUri="http://www.example.org/" Select="doc('data.xml')" /> <!-- bind parameter 'size' to the XPath expression '1024 * 768' --> <Parameter Name="size" Select="1024 * 768" /> <!-- bind parameter 'date' to the current date --> <Parameter Name="date" Select="current-date()" /> </StylesheetParameters> </PropertyGroup> <!-- test passing of serialization parameters --> <Target Name="transform"> <Transform Xsl="@(Stylesheet)" Input="@(ContextDocument)" InitialMode="{http://www.example.org/}classic" Collections="@(FooCollection);@(BarCollection)" Parameters="$(StylesheetParameters)" SerializationParameters="$(SerializationParameters)" Schemas="@(Schemas)" Validation="Schema" Output="output.htm"> <Output TaskParameter="OutputFiles" ItemName="TransformOutputFiles" /> </Transform> <Message Text="Wrote output file @(TransformOutputFiles)" /> </Target> </Project>