cancel
Showing results for 
Search instead for 
Did you mean: 

Xslt clarification

giridhar_vegi
Participant
0 Kudos

Hi Experts,

I am new to xslt. I am having the code could please explain in detail.

Thanks

Giridhar

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Giridhar,

The first line : <?xml version="1.0" encoding="UTF-8">

indicates that the XSLT is also in XML format with charset = UTF-8


The second line containing "http://www.w3.org/1999/XSL/Transform" points to the official W3C XSLT namespace. If this namespace is used XSLT version should be 1.0. Also the other namespace used in the same line is the input structure.

Third line : <xsl:output method="xml"/> indicates that output will be in XML format.

<xsl:template match="/"> indicates that the part of the input XML structure which is taken for processing is indicated by template, and the "match" shows that from that point of the input structure in XML the processing will take place. Please note that here match="/" means the entire body of the XML will be considered.

Line : <xsl:apply-templates mode="remprefix" select="*"/>. Here apply-templates indicates to which element the template is going to be applied. It works in accordance to the "select" used, based on "select" the child element that matches the value of the attribute is the one to which the template is applied. Here the operation to be done is indicated by mode="remprefix" which means remove prefix.

Here, since select="*" hence it refers to all the elements.

Remaining all the lines are with similar syntax. Hence will be helpful for you to understand

Regards,

Souvik

peter_wallner2
Active Contributor
0 Kudos

Hello Giridhar

,

The main template matches root (/) and applies

the template with mode="remprefix" selecting all elements (*).

The template match="*" mode="remprefix"

creates a variable which holds the local name of every matched element.

An element is this: <text> --> local name would be "text"

Then it applies the other template with mode="copyall" which matches attributes, comments, processing instructions and text.

What should happen from what I can see is that all attributes, comments, processing

instructions and text within an element are turned into elements themselves with

the name of the matched element.

For example

<?xml version="1.0" encoding="UTF-8"?>

<header>

    <text att="1234">

        <line>lladf</line>

    </text>

</header>

should turn into

<?xml version="1.0" encoding="UTF-8"?>

<header>

    <text>

        <text>1234</text>

        <line>lladf</line>

    </text>

</header>

But please try it with an example XML file to verify my statements.

Best regards,

Peter