简体   繁体   English

xslt获取先前的节点值

[英]xslt get preceding node value

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: 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. 我正在尝试获取与先前节点值相比具有不同值的当前num值。 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 但是,这不是删除重复项的好方法-请在此处查看原因: http : //www.jenitennison.com/xslt/grouping/muenchian.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM