Re: [xsl] saxon:evaluate() in schematron

Subject: Re: [xsl] saxon:evaluate() in schematron
From: ihe onwuka <ihe.onwuka@xxxxxxxxxxxxxx>
Date: Mon, 21 May 2012 19:23:13 +0100
Just a thought and please forgive me if it's not helpful.

I wonder if it would simplify things to break what you are doing up into
cases.

Case 1 - Is line wider than block
Case 2 - Is line taller than block

and then if neither of the above apply

Case 3 is the line within the block which would now simply be a check
against the extremum of the co-ordinates

On Mon, May 21, 2012 at 6:48 PM, Matthew Stoeffler
<Matthew.Stoeffler@xxxxxxxxxx> wrote:
> Hello.
>
> I'm working on a schematron script (iso schematron) in which I'm trying to
confirm a relationship between two elements representing containing boxes.
 So, source xml looks like 
>
> <ref id="r7">
>    <label>5</label>
>    <block n="10" page="p-65" x1="579" y1="4604" x2="2634" y2="4682"/>
>    <citation id="c19" citation-type="other">
>        <line n="10" page="p-65" x1="1690" y1="4604" x2="2612"
y2="4682"><![CDATA[Walther Straram, Paris, 193I]]></line>
>    </citation>
> </ref>
>
> . and the relationship I'm looking for is whether the line (or lines) are
within the block, and, most frustratingly, which coordinates are at fault if
it doesn't fit.
>
> My schematron pattern uses one function to ascertain whether or not the line
fits, and, if not, attempts to run the 'reportBadCoords' function to identify
which coordinates fail.  The function looks like this 
>
>  <xsl:function name="ins:reportBadCoords" as="xs:string">
>        <xsl:param name="coordNode" as="node()"/>
>        <xsl:param name="coordName" as="xs:string"/>
>        <xsl:param name="blockPath" as="xs:string"/>
>        <xsl:param  name="context" as="node()"/>
>        <xsl:variable as="xs:string" name="blkCoordPath"
select="concat('/',$blockPath,'/@',$coordName)"/>
>       <xsl:choose>
>           <xsl:when test="$coordName = 'x1'
>               and
number(saxon:evaluate(concat('$p1',$blkCoordPath),$context)) &lt;
number($coordNode)"><xsl:value-of select="$coordName"/></xsl:when>
>           <xsl:when test="$coordName = 'x2'
>               and
number(saxon:evaluate(concat('$p1',$blkCoordPath),$context)) &gt;
number($coordNode)"><xsl:value-of select="$coordName"/></xsl:when>
>           <xsl:when test="$coordName = 'y1'
>               and
number(saxon:evaluate(concat('$p1',$blkCoordPath),$context)) &lt;
number($coordNode)"><xsl:value-of select="$coordName"/></xsl:when>
>           <xsl:when test="$coordName = 'y2'
>               and
number(saxon:evaluate(concat('$p1',$blkCoordPath),$context)) &gt;
number($coordNode)"><xsl:value-of select="$coordName"/></xsl:when>
>          <!-- debugging -->
>           <xsl:otherwise><xsl:value-of
select="concat(saxon:evaluate(concat('$p1',$blkCoordPath),$context),'::',$coo
rdName,'::',$blkCoordPath,'::',$coordNode)"/>
>        </xsl:otherwise>
>        </xsl:choose>
>    </xsl:function>
>
> and is invoked from this rule.
>
>  <rule context="line">
>            <let name="lineNo" value="@n"/>
>            <let name="refId" value="ancestor::ref/@id"/>
>            <let name="artId"
value="ancestor::article/front/article-meta/article-id[@pub-id-type='doi']"/>
>            <assert test="some $bl in ancestor::ref/block
satisfies(ins:isContainedInBlock($bl, .))">
>                The current citation line (number: <value-of
select="$lineNo"/> ) does not fit within any of the defined blocks in the
containing ref (ref id = <value-of select="$refId"/>).
>                 [article id = <value-of select="$artId"/>].
>                Bad coords:
>                <value-of select="for $coord in
@*[matches(name(),'[xy][12]')] return
ins:reportBadCoords($coord,name($coord),functx:path-to-node-with-pos(ancestor
::ref/block),current())"/>
>            </assert>
>        </rule>
>
>
> When I test this script in Oxygen 13.2, with Saxon PE 9.305, I either fail
to return any value from the evaluate() function, or if I remove the reference
to context and just pass  $blkCoordPath straight to evaluate(), I get message
that I'm selecting root node without proper context, or context undefined.
>
> Thanks for any help.
>
> Matt S.

Current Thread