xslt获得先前的节点值(xslt get preceding node value)

编程入门 行业动态 更新时间:2024-10-17 09:49:06
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

更多推荐

本文发布于:2023-08-06 05:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444502.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   先前   xslt   preceding   node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!