Example

You can use the example provided here to know more about XSL based XML parser.

Input xml: birds.xml
<?xml version="1.0" encoding="UTF-8"?>
<Class>
<Order Name="TINAMIFORMES">
        <Family Name="TINAMIDAE">
            <Species Scientific_Name="Tinamus major">  Great Tinamou.</Species>
            <Species Scientific_Name="Nothocercus">Highland Tinamou.</Species>
            <Species Scientific_Name="Crypturellus soui">Little Tinamou.</Species>
            <Species Scientific_Name="Crypturellus cinnamomeus">
						Thicket Tinamou.</Species>
            <Species Scientific_Name="Crypturellus boucardi">Slaty-breasted 
						Tinamou.</Species>
            <Species Scientific_Name="Crypturellus kerriae">Choco Tinamou.</Species>
        </Family>
    </Order>
<Order Name="GAVIIFORMES">
        <Family Name="GAVIIDAE">
            <Species Scientific_Name="Gavia stellata">Red-throated Loon.</Species>
            <Species Scientific_Name="Gavia arctica">Arctic Loon.</Species>
            <Species Scientific_Name="Gavia pacifica">Pacific Loon.</Species>
            <Species Scientific_Name="Gavia immer">Common Loon.</Species>
            <Species Scientific_Name="Gavia adamsii">Yellow-billed Loon.</Species>
        </Family>
    </Order>
</Class>
Input XSL: birds.XSL
<?xml version="1.0" ?> 
<XSL:stylesheet xmlns:XSL="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <XSL:output method="xml" indent="yes" /> 
<XSL:template match="Class">
 <DocRoot>
  <XSL:for-each select="Order">
     <XSL:variable name="order"><XSL:value-of select="@Name" /> 
     </XSL:variable> 
     <XSL:for-each select="Family">
	    <Entry>
	    	<Attribute name="Order">
			<Value><XSL:value-of select="$order" /></Value> 
		</Attribute>
	   	<Attribute name="Family">
			<Value><XSL:value-of select="@Name" /></Value> 
	   	</Attribute>
	   	<Attribute name="Species">
		    <XSL:for-each select="Species">
      	    		<Value><XSL:value-of select="." /></Value> 
		    </XSL:for-each>
	   	</Attribute>
	    </Entry>
	 </XSL:for-each>
    </XSL:for-each>
 </DocRoot>
</XSL:template>
</XSL:stylesheet>

birds.xsl transforms birds.xml to IBM® Security Directory Integrator internal format from entry object with attribute value pairs, can be formed.

See Also

W3C Document Object Model
http://www.w3.org/DOM/

Effective XML processing with DOM and XPath in Java
http://www.ibm.com/developerworks/xml/library/x-domjava/