Good afternoon.
I'm fairly new to XML, XSD and XSLT and i'm facing the following issue: I have the following substructure in XSD, that can occur multiple times, which is part of a far larger structure which is irrelevant and i won't include for the sake of clarity:
<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>
Using XLST i'm supose to asure that if an element has a certain IDREF attribute value any repetition of the same value on the other elements should trigger a message on the stdout. To achieve this end i wrote the following lines in 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>
Which always prints Error in the html file, instead of doing so only when there are elements with the same values on IDREF. Both my understanding of the language and my search have not been able to help me understand this issue and how to solve it. Any ideas to why this might occur?
Kind regards
attribute::ref= ./@ref
is the same as @ref=@ref so is true whatever value of ref,
I'm not sure about the relevance of the XSD fragment (which doesn't mention ref) but perhaps you want
<xsl:if test="../contra[@ref=current()/@ref][2]">
Error
</xsl:if>
That tests if there are 2 (or more contra elements with the same ref as the current favor element, perhaps you want [1] or to use ../* rather than ../contra, it all depends. The question is not clear enough to be certain.