Reputation: 666
My aim i just to want to get the distinct the value, i mean, no of 10th td
value that is available in the second xml( xml file through 'document' function) and it should not be available in the source xml, this value i am treating as 'dintinct' value. How I can get this? I tried above code and it does not provide exact distinct values that i expect. Any help?
XSLT: How to compare two xml files and how to get distinct value from it based on this question, I tried the following with input xml files, but, even, i am not able to get the distinct text between two files.
For example, as per the correct result, here, this <distint>Meat and edible meat offal.</distint>
not supposed to come. But, right now, it is coming and this is wrong.
XSL file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:variable name="check" select="normalize-space(substring(//document[@indent='-2']/documenttitle,3))"/>
<xsl:template match="/">
<xsl:for-each select="document('Main2.xml')//*[local-name()='tr']/*[local-name()='td'][10][./preceding-sibling::td[5][. != '']]">
<xsl:choose>
<xsl:when test=". = $check">
</xsl:when>
<xsl:otherwise>
<xsl:text>
</xsl:text>
<distint><xsl:value-of select="."/></distint>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Source XML
<XML>
<documents>
<document indent="-3">
<document_prefixtitle>Some text</document_prefixtitle>
<document indent="-2"><documenttitle>1 Live animals.</documenttitle></document>
<document indent="-2"><documenttitle>2 Meat and edible meat offal.</documenttitle></document>
<document indent="-2"><documenttitle>3 Fish and crustaceans, molluscs and other aquatic invertebrates.</documenttitle></document>
<document indent="-2"><documenttitle>4 Dairy produce; birds eggs; natural honey; edible products of animal origin, not elsewhere specified or included.</documenttitle></document>
<document indent="-2"><documenttitle>5 Products of animal origin, not elsewhere specified or included.</documenttitle></document>
<document indent="-2"><documenttitle>6 Live trees and other plants; bulbs, roots and the like; cut flowers and ornamental foliage.</documenttitle></document>
<document indent="-2"><documenttitle>7 Edible vegetables and certain roots and tubers.</documenttitle></document>
<document indent="-2"><documenttitle>8 Edible fruit and nuts; peel of citrus fruit or melons.</documenttitle></document>
<document indent="-2"><documenttitle>9 Coffee, tea mat, and spices.</documenttitle></document>
<document indent="-2"><documenttitle>10 Cereals.</documenttitle></document>
<document indent="-2"><documenttitle>11 Products of the milling industry; malt; starches; inulin; wheat gluten.</documenttitle></document>
<document indent="-2"><documenttitle>12 Oil seeds and oleaginous fruits; miscellaneous grains, seeds and fruit; industrial or medicinal plants; straw and fodder.</documenttitle></document>
<document indent="-2"><documenttitle>13 Example of distint chaptrr fruits; miscellaneous grains</documenttitle></document>
<document indent="-2"><documenttitle>14 1Example of distint chaptrr fruits; miscellaneous grains</documenttitle></document>
</document></documents></XML>
XML that is taken through 'document' function is:
<table>
<tbody>
<tr>
<td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Live animals.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Meat and edible meat offal.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Fish and crustaceans, molluscs and other aquatic invertebrates.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Dairy produce; birds eggs; natural honey; edible products of animal origin, not elsewhere specified or included.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Products of animal origin, not elsewhere specified or included.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Live trees and other plants; bulbs, roots and the like; cut flowers and ornamental foliage.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Edible vegetables and certain roots and tubers.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Edible fruit and nuts; peel of citrus fruit or melons.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Coffee, tea mat, and spices.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Cereals.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Products of the milling industry; malt; starches; inulin; wheat gluten.</td></tr>
<tr><td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Oil seeds and oleaginous fruits; miscellaneous grains, seeds and fruit; industrial or medicinal plants; straw and fodder.</td></tr>
<tr>
<td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>17</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Live animals new sample.</td></tr>
<tr>
<td>Yes</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>18</td>
<td>_24</td>
<td>20141210</td>
<td>20141210</td>
<td></td><td>Active Live animals new sample.</td></tr>
</tbody>
</table>
As of now, am getting the result as follows
<?xml version="1.0" encoding="UTF-8"?>
<distint>Meat and edible meat offal.</distint>
<distint>Fish and crustaceans, molluscs and other aquatic invertebrates.</distint>
<distint>Dairy produce; birds eggs; natural honey; edible products of animal origin, not elsewhere specified or included.</distint>
<distint>Products of animal origin, not elsewhere specified or included.</distint>
<distint>Live trees and other plants; bulbs, roots and the like; cut flowers and ornamental foliage.</distint>
<distint>Edible vegetables and certain roots and tubers.</distint>
<distint>Edible fruit and nuts; peel of citrus fruit or melons.</distint>
<distint>Coffee, tea mat, and spices.</distint>
<distint>Cereals.</distint>
<distint>Products of the milling industry; malt; starches; inulin; wheat gluten.</distint>
<distint>Oil seeds and oleaginous fruits; miscellaneous grains, seeds and fruit; industrial or medicinal plants; straw and fodder.</distint>
<distint>Live animals new sample.</distint>
<distint>Active Live animals new sample.</distint>
Upvotes: 0
Views: 69
Reputation: 117018
The reson why this doesn't work is that you're comparing everything to $check
- but the $check
variable contains only this:
"Live animals."
This is because the substring()function (like all string functions) operates only on the first node in the node-set specified by the first argument.
If you want to strip the numbering from the <documenttitle>
nodes, you must do so for each and every one of them. And you cannot use substring(., 3)
because your numbers go above 9.
Upvotes: 1