xslt获得先前的节点值(xslt get preceding node value)
我试图访问前一个节点值,并将它与当前节点值进行比较,如果它们匹配的话。 请让我知道我哪里错了。
<?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>我试图获取与先前节点值相比具有不同值的当前num值。 模板中应该是什么条件?
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?
最满意答案
您的情况应该表示为:
<xsl:apply-templates select="num[not(preceding-sibling::node()[1] = .)]"/>或者 - 优选地 - 如:
<xsl:apply-templates select="num[not(preceding-sibling::num[1] = .)]"/>但是,这不是一个很好的方法来删除重复 - 请参阅这里为什么: http : //www.jenitennison.com/xslt/grouping/muenchian.html
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
更多推荐
发布评论