Monday, April 25, 2016

XSLT Transformation Script elements

Hi all,

Lets clarify some of elements in an XSLT transform script.

I used this scenario within WSO2 ESB "XSLT" mediator. When defining XSLT mediator u have to give exact transform script to run exact mediation function.

Lets consider about some of elements of xslt transform script.
  • Can use following two methods to declare XSL style sheet
<xsl:stylesheet version="1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">

OR

<xsl:transform version="1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">                          
  • <xsl:template> element is used to build templates.
"match" attribute used to associate with XML element. 

 <xsl:template match="/">  ----> This define consider whole document


Examples of match patterns:


<xsl:template match="table">
 
can be applied on any element named table.

<xsl:template match="x/y">

can be applied on any element named y whose parent is an element named x.

<xsl:template match="*">
can be applied to any element.

<xsl:template match="/*">

can be applied only to the top element of an XML document.

<xsl:template match="@*">

can be applied to any attribute.

<xsl:template match="text()">

can be applied to any text node.

<xsl:template match="comment()">

can be applied to any comment node.

<xsl:template match="processing-instruction()">

can be applied to any processing instruction node.

<xsl:template match="node()">

can be applied to any node: element, text, comment or processing instruction.


<xsl: output> element defines the format of the output document


<xsl:output method="xml|html|text|name"

version="string"

encoding="string"

omit-xml-declaration="yes|no"

standalone="yes|no"

doctype-public="string"

doctype-system="string"

cdata-section-elements="namelist"

indent="yes|no"

media-type="string"/>


<xsl:copy> element creates a copy of the current node. 

<xsl:copy use-attribute-sets="name-list">

  <!-- Content:template -->

</xsl:copy>

<xsl:apply-templates> element applies a template to the current element or to the current element's child nodes.

Like wise you can elements. In here, I summarised few of main elements. Value additions are welcome :)

No comments:

Post a Comment