This is related to my previous question but i can’t able to get solution for this. Here also i need to compare two node based on the attribute values but it’s difficult to me. Pls provide the xsl to do this. thanks in advance.
input.xml:
<comp>
<alink>
<link id="#c1-0003"/>
<link id="#c1-0001"/>
<link id="#c1-0002"/>
</alink>
<bibsection>
<bib id="c1-0001">
<citation>
<Name>Boud</Name> (<year>2007</year>)
<vol>32</vol> (<issue>3</issue>
</citation>
</bib>
<bib id="c1-0002">
<citation>
<Name>john</Name>(<year>2008</year>)
<vol>32</vol> (<issue>3</issue>)
</citation>
</bib>
<bib id="c1-0003">
<citation>
<name>nnc</name>(<year>2009</year>)
<vol>32</vol> (<issue>3</issue>)
</citation>
</bib>
</bibsection>
</comp>
output.xml:
<comp>
<alink>
<link id="#c1-0003"/>
<year>2009</year>
<link id="#c1-0001"/>
<year>2007</year>
<link id="#c1-0002"/>
<year>2008</year>
</alink>
<bibsection>
<bib id="c1-0001">
<citation>
<Name>Boud</Name> (<year>2007</year>)
<vol>32</vol> (<issue>3</issue>
</citation>
</bib>
<bib id="c1-0002">
<citation>
<Name>john</Name>(<year>2008</year>)
<vol>32</vol> (<issue>3</issue>)
</citation>
</bib>
<bib id="c1-0003">
<citation>
<name>nnc</name>(<year>2009</year>)
<vol>32</vol> (<issue>3</issue>)
</citation>
</bib>
</bibsection>
This transformation:
when applied on the provided XML document (corrected to contain different years):
produces the wanted, correct result:
Explanation:
This is one of the shortest, simplest, most readable and most efficient solution to the problem.
The only difference from the solution of the previous problem is that now the values of the
idattributes oflinkelements aren’t exactly the same as the value of theidattributes ofbibelements.We need to extract the substring of any value of the former type, starting from the 2nd character (that is, to skip the 1st character). This is natural to do using the standard XPath
substring()function.