I am trying to access the previous node value and compare it with current node value if they match. Please let me know where i am going wrong.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<nums>
<num>02</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>06</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<nums>
<xsl:apply-templates select=
"num[not(preceding-sibling::node()[1]=node()]"/>
</nums>
</xsl:template>
</xsl:stylesheet>
I am trying to fetch the current num values which have different value compared to previous node values. What should be my condition in templates?
Your condition should be expressed as:
<xsl:apply-templates select="num[not(preceding-sibling::node()[1] = .)]"/>
or - preferably - as:
<xsl:apply-templates select="num[not(preceding-sibling::num[1] = .)]"/>
However, this is not a good method to remove duplicates - see here why: http://www.jenitennison.com/xslt/grouping/muenchian.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.