Identity transform

The identity transform is a data transformation 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 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. This transformation uses the xsl:copy command[1] to perform the identity transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

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:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|*|processing-instruction()|comment()">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()|processing-instruction()|comment()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

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.0[2] 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:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:mode on-no-match="shallow-copy" />
</xsl:stylesheet>

is essentially equivalent to the earlier template rules. See the XSLT 3.0 standard's description of shallow-copy[3] 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. [1] For example:

<xsl:output method="xml" encoding="utf-8" cdata-section-elements="element-name-1 element-name-2"/>

Using XQuery

XQuery 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()) {
  element {node-name($element)}
    {$element/@*,
     for $child in $element/node()
        return if ($child instance of element())
          then local:copy($child)
          else $child
    }
};

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()* {
for $node in $input
   return 
      typeswitch($node)
        case document-node()
           return
              document {
                local:copy($node/node())
              }
        case element()
           return
              element {name($node)} {

                (: output each attribute in this element :)
                for $att in $node/@*
                   return
                      attribute {name($att)} {$att}
                ,
                (: output all the sub-elements of this element recursively :)
                for $child in $node
                   return local:copy($child/node())

              }
        (: otherwise pass it through.  Used for text(), comments, and PIs :)
        default return $node
};

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:copy-of select="."/>
  </xsl:template>
</xsl:stylesheet>

Using XProc

<p:pipeline name="pipeline" xmlns:p="http://www.w3.org/ns/xproc">
  <p:identity/>
</p:pipeline>

Here one important note about the XProc 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:

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- remove all social security numbers -->
  <xsl:template match="PersonSSNID"/>

Using XQuery

 declare function local:copy-filter-elements($element as element(), 
   $element-name as xs:string*) as element() {
   element {node-name($element) }
             { $element/@*,
               for $child in $element/node()[not(name(.)=$element-name)]
                  return if ($child instance of element())
                    then local:copy-filter-elements($child,$element-name)
                    else $child
           }
 };

To call this one would add:

$filtered-output := local:copy-filter-elements($input, 'PersonSSNID')

Using XProc

<p:pipeline name="pipeline" xmlns:p="http://www.w3.org/ns/xproc">
  <p:identity/>
  <p:delete match="PersonSSNID"/>
</p:pipeline>

See also

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

Read other articles:

Herbert James Draper, Halcyone, 1915. Dalam mitologi Yunani, Halkione (Bahasa Yunani: Ἁλκυόνη) adalah putri dari Aiolos, ibunya kemungkinan adalah Enarete atau Aigiale. Dia menikahi Keiks, putra Eosforos, Bintang Fajar. Dalam mitologi Halkionedan pasangannya sangat bahagia di Thrakia. Menurut Pseudo-Apollodoros, mereka sering saling memanggil dengan panggilan Zeus dan Hera. Ini membuat Zeus marah, jadi ketika Keiks sedang berlayar untuk berkonsultasi dengan orakel Delphi, Zeus melempa...

 

Basilika Bunda dari Kemurahan HatiBasilika Minor Bunda dari Kemurahan HatiSpanyol: Basílica Menor de Nuestra Señora de la Mercedcode: es is deprecated Basilika Bunda dari Kemurahan HatiLokasiYarumalNegara KolombiaDenominasiGereja Katolik RomaSejarahTanggal konsekrasi1944ArsitekturStatusBasilika minorStatus fungsionalAktifArsitekJosé María ZapataHeliodoro OchoaGayaNeo-RenaisansPeletakan batu pertama1861Selesai1944AdministrasiKeuskupanKeuskupan Santa Rosa de Osos Basilika Bunda dari Ke...

 

G30 beralih ke halaman ini. Untuk kegunaan lain, lihat G30 (disambiguasi). Group of ThirtyConsultative Group on International Economic and Monetary Affairs, Inc.Didirikan1978KetuaJean-Claude TrichetDirektur EksekutifStuart P. M. MackintoshStaf4Biaya$448k (FY07)Anggota30LokasiWashington, D.C.Alamat1726 M Street, NW, Suite 200 Washington, DC 20036 USASitus webwww.group30.org Group of Thirty, biasa disingkat G30, adalah organisasi pegiat keuangan dan akademisi internasional yang bertujuan memaha...

American diplomat This article is an orphan, as no other articles link to it. Please introduce links to this page from related articles; try the Find link tool for suggestions. (August 2020) Ana Colomar O'Brien (born November 16, 1938) is a Cuban-born American diplomat. The daughter of Fernando and Ana Colomar, she was born Ana Colomar in Havana and grew up in Mexico and Havana. She received a bachelor's degree from the Vedado Institute and a master's degree in English language and culture fr...

 

Voce principale: Associazione Calcio Monza Brianza 1912. Associazione Calcio MonzaStagione 1966-1967Sport calcio Squadra Monza Allenatore Luigi Radice Presidente Enzo Redaelli Serie C1º nel girone A (in Serie B) Maggiori presenzeCampionato: Ciceri e Sala (35) Miglior marcatoreCampionato: Sala (13) StadioGino Alfonso Sada 1965-1966 1967-1968 Si invita a seguire il modello di voce Questa pagina raccoglie le informazioni riguardanti l'Associazione Calcio Monza nelle competizioni ufficiali...

 

2014 American dystopian science fiction film The Maze RunnerTheatrical release posterDirected byWes BallScreenplay by Noah Oppenheim Grant Pierce Myers T.S. Nowlin Based onThe Maze Runnerby James DashnerProduced by Ellen Goldsmith-Vein Wyck Godfrey Marty Bowen Lee Stollman Starring Dylan O'Brien Ki Hong Lee Thomas Brodie-Sangster Kaya Scodelario Will Poulter Patricia Clarkson CinematographyEnrique ChediakEdited byDan ZimmermanMusic byJohn PaesanoProductioncompanies Gotham Group Temple Hill En...

City in Togdheer region, Somaliland City in Somaliland, SomalilandBurao Burco (Somali)برعو (Arabic)City FlagSealInteractive map outlining BuraoBuraoLocation in SomalilandShow map of TogdheerBuraoBurao (Somaliland)Show map of SomalilandBuraoBurao (Horn of Africa)Show map of Horn of AfricaBuraoBurao (Africa)Show map of AfricaCoordinates: 09°31′40.4″N 45°32′04.2″E / 9.527889°N 45.534500°E / 9.527889; 45.534500Country SomalilandRegionTogdheer...

 

Drachenbronn-Birlenbachcomune Drachenbronn-Birlenbach – Veduta LocalizzazioneStato Francia RegioneGrand Est Dipartimento Basso Reno ArrondissementWissembourg CantoneWissembourg AmministrazioneSindacoPierre Koepf TerritorioCoordinate48°59′12″N 7°52′16″E / 48.986667°N 7.871111°E48.986667; 7.871111 (Drachenbronn-Birlenbach)Coordinate: 48°59′12″N 7°52′16″E / 48.986667°N 7.871111°E48.986667; 7.871111 (Drachenbronn-Birlenbach)...

 

Questa voce sull'argomento attori statunitensi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Richard X. Slattery nel ruolo di William Halsey nella miniserie televisiva Venti di guerra Richard Xavier Slattery, noto come Richard X. Slattery (New York, 26 giugno 1925 – Los Angeles, 27 gennaio 1977), è stato un attore statunitense. Filmografia parziale Bus Stop – serie TV, episodio 1x23 (1962) Indir...

American college football season 1991 Kentucky Wildcats footballConferenceSoutheastern ConferenceRecord3–8 (0–7 SEC)Head coachBill Curry (2nd season)Offensive coordinatorRick Rhoades (1st season)Defensive coordinatorLarry New (2nd season)Home stadiumCommonwealth StadiumSeasons← 19901992 → 1991 Southeastern Conference football standings vte Conf Overall Team W   L   T W   L   T No. 7 Florida $ 7 – 0 – 0 10 – 2 ...

 

SN 2005cs di Galaksi Pusaran. SN 2005cs adalah sebuah ledakan supernova di berjarak 30 juta tahun cahaya di galaksi Pusaran (M51/NGC 5194). Ini adalah supernova kedua di M51 11 tahun. Spektrum berikutnya dari supernova yang sangat redup ini, mengungkapkan sebagai peristiwa Tipe II. SN 2005cs adalah supernova tipe II yang terjadi di lengan spiral galaksi, kira-kira berlawanan dengan NGC 5195 dan diamati oleh astronom amatir Jerman, Werner Klug dan Hermann von Eiff pada 9 Juli, lebih dari semin...

 

Erula ÈrulaKomuneComune di ErulaLokasi Erula di Provinsi SassariNegaraItaliaWilayah SardiniaProvinsiSassari (SS)Pemerintahan • Wali kotaMarianna FuscoLuas • Total39,31 km2 (15,18 sq mi)Ketinggian457 m (1,499 ft)Populasi (2016) • Total745[1]Zona waktuUTC+1 (CET) • Musim panas (DST)UTC+2 (CEST)Kode pos07030Kode area telepon079Situs webhttp://www.comunedierula.it Erula (bahasa Sardinia: Èrula) adalah sebuah k...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (نوفمبر 2018) منظمة مساعدة المرأةالتاريخالتأسيس 1982 الإطارالنوع منظمة غير حكومية التنظيمموقع الويب wao.org.my تعديل - تعديل مصدري - تعديل ويكي بيانات منظمة مساعدة المرأة هي م�...

 

The effect of total control in a battlespace Part of a series onWarOutline History Prehistoric Ancient Post-classical castles Early modern pike and shot napoleonic Late modern industrial fourth-gen Military Organization Command and control Defense ministry Army Navy Air force Marines Coast guard Space force Reserves Regular / Irregular Ranks Specialties: Staff Engineers Intelligence Reconnaissance Medical Military police Land units: Infantry Armor Cavalry Artillery Special forces Signal corps...

 

波兰共和国Rzeczpospolita Polska1918年—1939年 国旗 (1928-1939) 国徽 国歌:Mazurek Dąbrowskiego《波兰永不灭亡》 波兰第二共和国(约1930年)首都华沙常用语言波兰语(官方)、乌克兰语、白俄罗斯语、俄语、立陶宛语、德语、意地绪语宗教罗马天主教犹太教政府共和国总统 • 1918–1922 约瑟夫·毕苏斯基• 1922 加布里埃尔·纳卢托维奇• 1922–1926 斯坦尼斯瓦夫·沃伊切�...

Advisory circularFAA PublicationAbbreviationACOrganizationFederal Aviation AdministrationDomainAviation safetyWebsiteFAA Advisory Circulars (ACs) Advisory circular (AC) refers to a type of publication offered by the Federal Aviation Administration (FAA) to provide a single, uniform, agency-wide system … to deliver advisory (non-regulatory) material to the aviation community.[1] Advisory circulars are now harmonized with soft law Acceptable Means of Compliance (AMC) publications of E...

 

Part of a series onMachine learningand data mining Paradigms Supervised learning Unsupervised learning Online learning Batch learning Meta-learning Semi-supervised learning Self-supervised learning Reinforcement learning Curriculum learning Rule-based learning Quantum machine learning Problems Classification Generative modeling Regression Clustering Dimensionality reduction Density estimation Anomaly detection Data cleaning AutoML Association rules Semantic analysis Structured prediction Fea...

 

Swiss freestyle wrestler Fritz HagmannBorn(1901-03-28)28 March 1901Died14 December 1974(1974-12-14) (aged 73) Medal record Men's freestyle wrestling Representing  Switzerland Olympic Games 1924 Paris Middleweight Fritz Hagmann (28 March 1901 – 14 December 1974) was a Swiss freestyle wrestler and Olympic champion. He won a gold medal at the 1924 Summer Olympics in Paris.[1][2] Beside that he was a successful Schwinger and member of the Schwingklub Winterthur. But he...

В Википедии есть статьи о других людях с такой фамилией, см. Евстафьев; Евстафьев, Николай. Николай Павлович Евстафьев Дата рождения 19 июля 1925(1925-07-19) Место рождения деревня Ельцово ныне Новодугинский район Смоленской области Дата смерти 28 июня 1993(1993-06-28) (67 лет) Место �...

 

Cet article est une ébauche concernant le rugby à XV et la Lituanie. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Lituanie Données clés Entrée au Board 1992 Sélectionneur Irmantas Kukulskis Capitaine Mindaugas Misevičius Record de sélections Mindaugas Misevičius et Laurynas Tipelis (45) Record de points Kęstutis Macišauskas (272) Premier match officiel1er mai 1993 Allemagne 31 - 5 Lituanie Plus lar...