I need to convert an xml using xsl file, the question is: I have several tag with the same name but different attribute, I've to convert them changing their name with the name of their attribute and print their value. Here the sample:
<INDEX_FIELDS>
<FIELD NAME= "Field1" VALUE= "value1"/>
<FIELD NAME= "Field2" VALUE= "value2"/>
<FIELD NAME= "Field3" VALUE= "value3"/>
<FIELD NAME= "Field4" VALUE= "value4"/>
</INDEX_FIELDS>
I want make it like this sample:
<INDEX_FIELD>
<FIELD1>VALUE1</FIELD1>
<FIELD2>VALUE2</FIELD2>
<FIELD3>VALUE3</FIELD3>
<FIELD4>VALUE4</FIELD4>
</INDEX_FIELD>
I could use only xsl transformation. Someone can give me any help? I've visited W3C school site, tried several method but nothing seem's to work. Thanks to anyone will answer.
Here my xslt:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<ROOT>
<HEAD>
<TAG><xsl_value-of select="ROOT/HEAD/TAG"/></TAG>
<-- Several tag -->
</HEAD>
<BODY>
<DOCUMENTS><--Here it is a list of documents -->
<xsl:for-each select="ROOT/BODY/DOCUMENTS/DOCUMENT">
<DOCUMENT>
<xsl:for-each select="INDEX_FIELDS/FIELD">
enter code here
</xsl:for-each>
<-- Closing tags -->
There is no need to use for-each loops. You can also use
xsl:template match
rules that match one part of your XML document. This rule will be executed every time a match occurs in the XMLAlternative way to structure your XSLT:
XSLT tutorial: http://edutechwiki.unige.ch/en/XSLT_Tutorial_-_Basics#A_first_glance_at_XSLT
XSLT works a bit differently to many programming languages: instead of a list of instructions with subroutines etc, you specify a list of possible nodes in your source document and what to do with them.