i’m new to xslt pls provide the xslt that compare two node based on the attribute values.
input.xml:
<comp>
<alink>
<link id="0003"/>
<link id="0001"/>
<link id="0002"/>
</alink>
<bibsection>
<bib id="0001">2007</bib>
<bib id="0002">2008</bib>
<bib id="0003">2009</bib>
</bibsection>
</comp>
my output should be,
output.xml:
<comp>
<alink>
<link id="0003"/><year>2009</year>
<link id="0001"/><year>2007</year>
<link id="0002"/><year>2008</year>
</alink>
<bibsection>
<bib id="0001">2007</bib>
<bib id="0002">2008</bib>
<bib id="0003">2009</bib>
</bibsection>
</comp>
thanks in advance.
A complete, efficient and short transformation, using keys:
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
Explanation:
The identity rule copies every matched node “as-is”.
There is a single template overriding the identity template — and it matches any
linkelement. The code in the body of this template calls the identity template by name to process the matchedlinkelement, then constructs ayearelement, with a text node child whose value is the string value of the firstbibelement whoseidattribute has the same value as theidattribute of the matchedlinkelement. Selecting thisbibelement is done using thekey()function that references anxsl:keyinstruction named “kBibById”.Notice:
The link to the identity rule above is temporarily inoperable — for the time-being, please, use this one form the Internet Archives:
http://web.archive.org/web/20081229160200/http://www.dpawson.co.uk/xsl/sect2/identity.html