Xml - XSL Transformations (XSLT)

About

XSLT is the most important part of XSL.

Extensible Stylesheet Language Transformation (XSLT):

  • is a language for transforming XML documents into other XML documents (and particularly into (X)HTML documents).
  • specify transformations on the data in order to convert it
  • uses XPath (mechanisms for addressing XML data) to navigate in XML documents

See template for processing

Example

With the xsltproc xml command line utility

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text"/>

    <xsl:template match="poc">
        Ref:
        <xsl:value-of select="ref"/>
        Name: <xsl:value-of select="lastName"/>,
        <xsl:value-of select="firstName"/>
        <xsl:value-of select="middleName"/>
        Handle:
        <xsl:value-of select="handle"/>
        Company:
        <xsl:value-of select="companyName"/>
        Address:
        <xsl:value-of select="streetAddress"/>
        City:
        <xsl:value-of select="city"/>
        StateProv:
        <xsl:value-of select="iso3166-2"/>
        Country:
        <xsl:value-of select="iso3166-1/code2"/>
        RegDate:
        <xsl:value-of select="registrationDate"/>
        <xsl:text>sampletext</xsl:text>
    </xsl:template>

</xsl:stylesheet>
  • Command
xsltproc poc.xsl http://whois.arin.net/rest/poc/KOSTE-ARIN    
  • Output:
Ref:       http://whois.arin.net/rest/poc/KOSTE-ARIN  
Name:      Kosters, Mark  
Handle:    KOSTE-ARIN  
Company:   ARIN  
Address:   PO Box 232290  
City:      Centreville  
StateProv: VA  
Country:   US  
RegDate:   2009-10-02T11:54:45-04:00

Documentation / Reference

Task Runner