Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle <constraintDecl> from extract-isosch.xsl #698

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Test/expected-results/test.isosch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>ISO Schematron rules</title>
<!-- DELETED TIMESTAMP. -->
Expand Down
38 changes: 17 additions & 21 deletions odds/extract-isosch.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ of this software, even if advised of the possibility of such damage.
is a direct child of <d:pre>&lt;schemaSpec</d:pre>.</d:p>
</d:desc>
</d:doc>
<xsl:output encoding="utf-8" indent="yes" method="xml"/>
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:param name="verbose" select="'false'"/>
<xsl:param name="lang" select="'en'"/>
<d:doc>
Expand All @@ -129,7 +129,9 @@ of this software, even if advised of the possibility of such damage.
<xsl:param name="teix-ns" select="'http://www.tei-c.org/ns/Examples'"/>
<xsl:variable name="xsl-ns">http://www.w3.org/1999/XSL/Transform</xsl:variable>


<xsl:mode on-no-match="shallow-copy" name="copy"/>
<xsl:mode on-no-match="shallow-copy" name="NSdecoration"/>

<d:doc>
<d:desc>Note on keys: should not really need the "[not(ancestor::teix:egXML)]"
predicate on DEPRECATEDs and CONSTRAINTs, as the elements matched (tei:* and
Expand Down Expand Up @@ -170,20 +172,14 @@ of this software, even if advised of the possibility of such damage.
<!-- from "schematron-extraction" to "copy". -->
</xsl:template>

<xsl:template match="@*|node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="copy"/>
</xsl:copy>
</xsl:template>

<d:doc>
<d:desc>First pass ... outermost element gets a new @xml:lang iff it doesn't
have one already</d:desc>
</d:doc>
<xsl:template match="/*" mode="NSdecoration">
<xsl:copy>
<xsl:apply-templates select="@* except @xml:lang" mode="#current"/>
<xsl:attribute name="xml:lang" select="'en'"/>
<xsl:attribute name="xml:lang" select="$lang"/>
<xsl:apply-templates select="@xml:lang" mode="#current"/>
<xsl:apply-templates select="node()" mode="#current"/>
</xsl:copy>
Expand Down Expand Up @@ -232,21 +228,13 @@ of this software, even if advised of the possibility of such damage.
</xsl:copy>
</xsl:template>

<d:doc>
<d:desc>First pass ... everything else just gets copied</d:desc>
</d:doc>
<xsl:template match="@*|node()" mode="NSdecoration">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="NSdecoration"/>
</xsl:copy>
</xsl:template>

<d:doc>
<d:desc>Second pass does most the work ...</d:desc>
</d:doc>
<xsl:template match="/" mode="schematron-extraction">
<xsl:param name="decorated" as="element()"/>
<schema queryBinding="xslt2">
<xsl:variable name="qb" select="( //tei:constraintDec[ @scheme eq 'schematron']/@queryBinding, 'xslt2')[1]"/>
sydb marked this conversation as resolved.
Show resolved Hide resolved
<schema queryBinding="{$qb}">
<title>ISO Schematron rules</title>
<xsl:comment> This file generated <xsl:sequence select="tei:whatsTheDate()"/> by 'extract-isosch.xsl'. </xsl:comment>

Expand Down Expand Up @@ -274,8 +262,8 @@ of this software, even if advised of the possibility of such damage.
<!-- if desired, other NSs can be added manually here -->
</xsl:variable>
<xsl:variable name="NSs" select="distinct-values( $allNSs )"/>
<!-- For each pair (except those that are empty or are the XLS namespace) ... -->
<xsl:for-each select="$NSs[ not(. eq '␝') and not( contains( ., $xsl-ns ) ) ]">
<!-- For each pair (except those that are empty or are the XSL namespace) ... -->
<xsl:for-each select="$NSs[ not( . eq '␝' or contains( ., $xsl-ns ) ) ]">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here seems slightly inaccurate, since this is saying all of the $NSs except the ones that are equal to the group separating character (␝)(https://www.compart.com/en/unicode/U+241D)or that contain the XSL namespace. I would assume this means that empty ones could conceivably make it through?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh … No to the ultimate question, but maybe phrasing and test should be a little more precise, here.
An “empty” one, i.e. (presumably) an element that has been decorated with both an empty @nsp and an empty @nsu would end up being the single character , and thus match the first comparison.
The contains() is meant to ensure that we do not generate a <sch:ns> for the XSLT namespace here in the implicit section. (I am not sure why we are worried about it — would it hurt anything if it were generated?) But of course it is not testing equality, so in fact if someone (bizarrely) had a namespace URI of “this-is-not-http://www.w3.org/1999/XSL/Transform_NOT”, this test would incorrectly see it as the XSLT namespace and fail to generate the needed <sch:ns>. So I think that should be updated to matches( ., '␝'||$xsl-ns||'$').

<xsl:sort/>
<!-- ... parse out the prefix and the URI (using that never-occurs character) -->
<xsl:variable name="nsp" select="substring-before( .,':␝')"/>
Expand Down Expand Up @@ -308,6 +296,14 @@ of this software, even if advised of the possibility of such damage.
schema that does not perform the desired constraint tests properly.</xsl:message>
</xsl:if>

<xsl:if test="$decorated//tei:constraintDecl[ @scheme eq 'schematron']">
<xsl:call-template name="blockComment">
<xsl:with-param name="content" select="'declarations:'"/>
</xsl:call-template>
<xsl:apply-templates mode="copy"
select="//tei:constraintDecl[ @scheme eq 'schematron']/*[not(self::sch:ns)]"/>
</xsl:if>

<xsl:if test="key('CONSTRAINTs',1)">
<xsl:call-template name="blockComment">
<xsl:with-param name="content" select="'constraints:'"/>
Expand Down
Loading