Schematron and Java

Here should go questions about transforming XML with XSLT and FOP.
drakend
Posts: 1
Joined: Thu Feb 04, 2010 11:15 pm

Schematron and Java

Post by drakend »

Hello,
I have an xml file structured like this:

Code: Select all


<root>    
<nodeA>
<nodeB>
<nodeC>0</esiste>
<nodeD>abcd</id_tensione>
<nodeE>abcd</nodeE>
<nodeF>0</metri>
</nodeB>
<nodeB>
<nodeC>0</esiste>
<nodeD>abcd</nodeD>
<nodeE>abcd</nodeE>
<nodeF>0</nodeF>
</nodeB>
</nodeA>
<nodeA>
<nodeB>
<nodeC>0</nodeC>
<nodeD>abcd</nodeD>
<nodeE>abcd</nodeE>
<nodeF>0</nodeF>
</nodeB>
<nodeB>
<nodeC>0</nodeC>
<nodeD>abcd</nodeD>
<nodeE>abcd</nodeE>
<nodeF>0</nodeF>
</nodeB>
</nodeA>
</root>
I validate this xml (I omitted the headers) with this schematron rule called from Java code:

Code: Select all


    <iso:pattern>
<iso:rule context="nodeB">
<assert test="exists(nodeF) and nodeF > 0">nodeA[<value-of select="(index-of(../../nodeA, ..)-1)" />].nodeB[<value-of select="(index-of(../nodeB, self::node())-1)" />].nodeF#Some message.
</assert>
</iso:rule>
</iso:pattern>
The sequence index for nodeB is displayed correctly, while the sequence index of nodeA creates problems. It says the operator - cannot operate on a sequence than more than one number, meaning index-of returns more than one index for nodeA. How can this happen? How can avoid it?
Thanks! :)
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Schematron and Java

Post by george »

The index-of returns a sequence. Note that what you want is to check for a specific node and in that case you should use generate-id() to obtain a unique number for that node, something like

Code: Select all


index-of(../../nodeA/generate-id(), ../generate-id())-1)
You need a similar change also for nodeB.

Best Regards,
George
George Cristian Bina
Post Reply