It's two queries but both similar (I think) and both involve counting or subtracting values from elements.


I need process the sample input file below so that elements marked with <!-- must be counted --> get counted and that the elements <fpage> and <lpage> get subtracted. The counts and subtraction should then create a <counts> element like illustrated on the expected output file below.


Problem: needs to get done using xslt version 1.0


sample input file:



<article>
<front>
<article-meta>
<fpage>100</fpage> <!-- first page -->
<lpage>117</lpage> <!-- last page -->
</article-meta>
</front>
<body>
<table-wrap></table-wrap> <!-- must be counted -->
<fig></fig> <!-- must be counted -->
<fig></fig> <!-- must be counted -->
<disp-formula></disp-formula> <!-- must be counted -->
</body>
<back>
<ref-list>
<ref></ref> <!-- must be counted -->
<ref></ref> <!-- must be counted -->
<ref></ref> <!-- must be counted -->
<ref></ref> <!-- must be counted -->
<ref></ref> <!-- must be counted -->
</ref-list>
</back>
</article>


expected output file:



<article>
<front>
<article-meta>
<fpage>100</fpage> <!-- first page -->
<lpage>117</lpage> <!-- last page -->
<counts> <!-- this element must be created using XSLT -->
<table-count count="1"/> <!-- should get the total number of <table-wrap> elements -->
<ref-count count="5"/> <!-- should get the total number of <ref> elements -->
<fig-count count="2"/> <!-- should get the total number of <fig> elements -->
<eqs-count count="1"/> <!-- should get the total number of <disp-formula> elements -->
<page-count count="17"/> <!-- should get the value of <lpage> minus <fpage> elements -->
</counts>
</article-meta>
</front>
<body>
<table-wrap></table-wrap>
<fig></fig>
<fig></fig>
<disp-formula></disp-formula>
</body>
<back>
<ref-list>
<ref></ref>
<ref></ref>
<ref></ref>
<ref></ref>
<ref></ref>
</ref-list>
</back>
</article>


Any idea how to do that??


No comments:

Post a Comment