HOME

TheInfoList



OR:

The identity transform is a
data transformation In computing, data transformation is the process of converting data from one format or structure into another format or structure. It is a fundamental aspect of most data integrationCIO.com. Agile Comes to Data Integration. Retrieved from: https ...
that copies the source data into the destination data without change. The identity transformation is considered an essential process in creating a reusable transformation library. By creating a library of variations of the base identity transformation, a variety of data transformation filters can be easily maintained. These filters can be chained together in a format similar to
UNIX Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
shell pipes.


Examples of recursive transforms

The "copy with recursion" permits, changing little portions of code, produce entire new and different output, filtering or updating the input. Understanding the "identity by recursion" we can understand the filters.


Using XSLT

The most frequently cited example of the identity transform (for XSLT version 1.0) is the "copy.xsl" transform as expressed in
XSLT XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text, or XSL Formatting Objects. These formats c ...
. This transformation uses the xsl:copy commandW3.org - XSL Transformations Version 1.0 - Copying
/ref> to perform the identity transformation: This template works by matching all attributes (@*) and other nodes (node()), copying each node matched, then applying the identity transformation to all attributes and child nodes of the context node. This recursively descends the element tree and outputs all structures in the same structure they were found in the original file, within the limitations of what information is considered significant in the XPath data model. Since node() matches text, processing instructions, root, and comments, as well as elements, all XML nodes are copied. A more explicit version of the identity transform is: This version is equivalent to the first, but explicitly enumerates the types of XML nodes that it will copy. Both versions copy data that is unnecessary for most XML usage (e.g., comments).


XSLT 3.0

XSLT 3.0W3.org - XSL Transformations Version 3.0
/ref> specifies an on-no-match attribute of the xsl:mode instruction that allows the identity transform to be declared rather than implemented as an explicit template rule. Specifically: is essentially equivalent to the earlier template rules. See the XSLT 3.0 standard's description of shallow-copyW3.org - XSL Transformations Version 3.0 - Built-in Templates: Shallow Copy
/ref> for details. Finally, note that markup details, such as the use of CDATA sections or the order of attributes, are not necessarily preserved in the output, since this information is not part of the XPath data model. To show CDATA markup in the output, the XSLT stylesheet that contains the identity transform template (''not'' the identity transform template itself) should make use of the xsl:output attribute called cdata-section-elements. cdata-section-elements specifies a list of the names of elements whose text node children should be output using CDATA sections. For example:


Using XQuery

XQuery XQuery (XML Query) is a query language and functional programming language designed to query and transform collections of structured and unstructured data, primarily in the form of XML. It also supports text data and, through implementation-sp ...
can define recursive functions. The following example XQuery function copies the input directly to the output without modification. declare function local:copy($element as element()) ; The same function can also be achieved using a typeswitch-style transform. xquery version "1.0"; (: copy the input to the output without modification :) declare function local:copy($input as item()*) as item()* ; The typeswitch transform is sometime preferable since it can easily be modified by simply adding a case statement for any element that needs special processing.


Non-recursive transforms

Two simple and illustrative "copy all" transforms.


Using XSLT


Using XProc

Here one important note about the
XProc XProc is an XML transformation language for processing documents in pipelines: chaining conversions and other steps together to achieve the desired results. It can handle documents in XML, HTML, JSON, text and binary. The current (stable) versi ...
identity, is that it can take either one document like this example or a sequence of document as input.


More complex examples

Generally the identity transform is used as a base on which one can make local modifications.


Remove named element transform


Using XSLT

The identity transformation can be modified to copy everything from an input tree to an output tree except a given node. For example, the following will copy everything from the input to the output except the social security number:


Using XQuery

declare function local:copy-filter-elements($element as element(), $element-name as xs:string*) as element() ; To call this one would add: $filtered-output := local:copy-filter-elements($input, 'PersonSSNID')


Using XProc


See also

*
Data mapping In computing and data management, data mapping is the process of creating data element mappings between two distinct data models. Data mapping is used as a first step for a wide variety of data integration tasks, including: * Data transforma ...
* XML pipeline


Further reading

* ''XSLT Cookbook'', O'Reilly Media, Inc., December 1, 2002, by Sal Mangano, {{ISBN, 0-596-00372-2 * Priscilla Walmsley, ''XQuery'', O'Reilly Media, Inc., Chapter 8 Functions – Recursive Functions – page 109


References

Computer programming Transforms