下午好。
我对 XML、XSD 和 XSLT 还很陌生,我面临以下问题:我在 XSD 中有以下子结构,它可能会发生多次,这是一个更大的结构的一部分,它是无关紧要的,我不会为了清楚起见,包括:
<xs:complexType name= "listavotosmocao">
<xs:choice maxOccurs="unbounded">
<xs:element name="favor" type="pessoaref"/>
<xs:element name="contra" type="pessoaref"/>
<xs:element name="abstiveram" type="pessoaref"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="pessoaref">
<xs:attribute ref="id" type="xs:string"/>
</xs:complexType>
使用 XLST 我想确保如果一个元素具有某个 IDREF 属性值,则其他元素上相同值的任何重复都应该在标准输出上触发一条消息。为了达到这个目的,我在 XSLT 中写了以下几行:
<xsl:for-each select="votacao//favor">
<xsl:if test="(count(preceding-sibling::contra[attribute::ref= ./@ref])
+ count(following-sibling::contra[attribute::ref=./@ref]) )> 0">
Error
</xsl:if>
</xsl:for-each>
它总是在 html 文件中打印错误,而不是仅在 IDREF 上存在具有相同值的元素时才这样做。我对语言的理解和我的搜索都无法帮助我理解这个问题以及如何解决它。关于为什么会发生这种情况的任何想法?
亲切的问候