Schematron position() bug
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 125
- Joined: Mon Jun 09, 2003 6:02 pm
- Location: Charlottesville, Virginia USA
Schematron position() bug
It seems that the Schematron validation included with oXygen has a bug involving XPath tests with position().
Consider this sample XML file:
I want to enforce a rule that every row must have an @n attribute containing the row number. This Schematron rule should do it:
But it does not work under oXygen 5.1 (OS X version). All the rows fail.
After some experiment, I discovered that the rows all return true() for the tests if I change
to
So it seems that the true position is being multiplied by 2 somewhere in the underlying Schematron code.
I tested this data and my original Schematron rule using Jing (version 20030619) and it performed as expected.
Then I downloaded the Skeleton 1.5 files from http://xml.ascc.net/schematron/1.5/ and tried running the code using a command-line XSLT processor. This produced the bug also. But I can't figure out where the problem is in Skeleton.
Since oXygen already comes with Jing, maybe Jing could be used for the Schematron support? See:
http://www.thaiopensource.com/relaxng/jing-other.html
Consider this sample XML file:
Code: Select all
<test>
<table>
<row n="1">
<cell>one</cell>
<cell>two</cell>
</row>
<row n="2">
<cell>un</cell>
<cell>deux</cell>
</row>
<row n="3">
<cell>uno</cell>
<cell>dos</cell>
</row>
</table>
</test>
Code: Select all
<sch:rule context="row">
<sch:assert test="@n and ( position() = @n )">Each row should be
numbered sequentially using the @n attribute</sch:assert>
</sch:rule>
After some experiment, I discovered that the rows all return true() for the tests if I change
Code: Select all
position() = @n
Code: Select all
position() = @n* 2
I tested this data and my original Schematron rule using Jing (version 20030619) and it performed as expected.
Then I downloaded the Skeleton 1.5 files from http://xml.ascc.net/schematron/1.5/ and tried running the code using a command-line XSLT processor. This produced the bug also. But I can't figure out where the problem is in Skeleton.
Since oXygen already comes with Jing, maybe Jing could be used for the Schematron support? See:
http://www.thaiopensource.com/relaxng/jing-other.html
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi David,
The result given by the Schematron validation in oXygen takes into account the text nodes that you have between the row elements. If you elliminate those nodes you will get the document validated.
You can use Jing to validate with a Schematon schema if you place that in a NRL schema like below:
and then validate with that NRL schema.
A more roboust approach will be if you change your Schematron rule as follows:
Best Regards,
George
The result given by the Schematron validation in oXygen takes into account the text nodes that you have between the row elements. If you elliminate those nodes you will get the document validated.
You can use Jing to validate with a Schematon schema if you place that in a NRL schema like below:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://www.thaiopensource.com/validate/nrl">
<anyNamespace>
<validate schema="test.sch"/>
</anyNamespace>
</rules>
A more roboust approach will be if you change your Schematron rule as follows:
Code: Select all
<sch:rule context="row">
<sch:assert test="@n and ( count(preceding-sibling::row) = @n - 1 )">Each row should be
numbered sequentially using the @n attribute</sch:assert>
</sch:rule>
George
-
- Posts: 125
- Joined: Mon Jun 09, 2003 6:02 pm
- Location: Charlottesville, Virginia USA
Thanks, but confused
George, thanks for the revised Schematron rule. I am still confused about whether the Skeleton 1.5 validation is correct or buggy. If I write an XSLT script to report position() for each row in the sample XML file:
it produces the output "1 2 3" using any of the XSLT parsers in oXygen. So I would expect a Schematron rule with context "row" and test "position()" to give the same result.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="//row">
<xsl:value-of select="position()"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi David,
Skeleton does not work like that, it uses templates to match the row elements. So it does something like:
and a default template will be also applied on the table element:
As you can see this will get the text nodes when you use position.
Best Regards,
George
Skeleton does not work like that, it uses templates to match the row elements. So it does something like:
Code: Select all
<xsl:template match="row">
<xsl:value-of select="position()"/>
<xsl:text> </xsl:text>
</xsl:template>
Code: Select all
<xsl:template match="table">
<xsl:apply-templates select="node()"/>
</xsl:template>
Best Regards,
George
Last edited by george on Thu Jan 27, 2005 10:58 am, edited 1 time in total.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service