Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 15 additions & 3 deletions src/main/resources/content/xml/xproc/evaluate/compare.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@
</p:otherwise>
</p:choose>
<p:identity name="alternate"/>

<p:compare name="compare">
<p:with-option name="fail-if-not-equal" select="$fail-if-not-equal"/>

<p:xslt name="ignores">
<p:input port="source">
<p:pipe port="result" step="source"/>
<p:pipe port="result" step="alternate"/>
</p:input>
<p:input port="stylesheet">
<p:document href="ignore.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>



<p:compare name="compare">
<p:with-option name="fail-if-not-equal" select="$fail-if-not-equal"/>
<p:input port="alternate">
<p:pipe port="result" step="alternate"/>
</p:input>
Expand Down
88 changes: 88 additions & 0 deletions src/main/resources/content/xml/xproc/evaluate/ignore.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:x="http://www.daisy.org/ns/xprocspec"
exclude-result-prefixes="#all"
version="2.0">
<xsl:variable name="alternate" select="collection()[2]"/>
<xsl:variable name="ignore-nodes" select="x:ignore-node-paths($alternate)"/>

<xsl:key name="node-path" match="@* | node()" use="x:path(.)"/>

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

<xsl:template match="key('node-path', $ignore-nodes)">
<xsl:choose>
<xsl:when test="self::text()">
<xsl:text>...</xsl:text>
</xsl:when>
<xsl:when test="self::element()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:text>...</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:when test="self::attribute()">
<xsl:attribute name="{name()}" select="'...'" namespace="{namespace-uri()}"/>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:function name="x:ignore-node-paths" as="xs:string*">
<xsl:param name="alternate" as="document-node()"/>
<xsl:variable name="ignore-text" select="$alternate//text()[. = '...']"/>
<xsl:variable name="ignore-text" select="$ignore-text / x:path(parent::*)"/>
<xsl:variable name="ignore-attr" select="$alternate//@*[. = '...']/x:path(.)"/>

<xsl:sequence select="$ignore-text, $ignore-attr"/>

</xsl:function>

<xsl:function name="x:path" as="xs:string">
<xsl:param name="node" as="node()"/>
<xsl:variable name="parent-path" select="
if ($node instance of document-node()) then '' else x:path($node/parent::node())
"/>
<xsl:variable name="node-name" select="x:node-name($node)"/>
<xsl:variable name="node-position" select="
count($node/preceding-sibling::node()[x:node-name(.) = $node-name]) + 1
"/>
<xsl:variable name="predicate" select="
if ($node instance of attribute()) then '' else concat('[', $node-position, ']')
"/>

<xsl:sequence select="concat($parent-path, '/', $node-name, $predicate)"/>
</xsl:function>

<xsl:function name="x:node-name" as="xs:string">
<xsl:param name="node" as="node()"/>

<xsl:variable name="namespace" select="$node/namespace-uri()"/>
<xsl:variable name="name" select="concat('Q{', $namespace, '}', local-name($node))"/>

<xsl:sequence select="
if ($node instance of text())
then 'text()'
else if ($node instance of comment())
then 'comment()'
else if ($node instance of processing-instruction())
then 'processing-instruction()'
else if ($node instance of document-node())
then ''
else if ($node instance of element())
then $name
else if ($node instance of attribute() and $namespace = '')
then local-name($node)
else if ($node instance of attribute())
then $name
else ''
"/>

</xsl:function>

</xsl:stylesheet>
47 changes: 47 additions & 0 deletions src/test/xprocspec/tests/ignore-1.xprocspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.daisy.org/ns/xprocspec/xprocspec.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<x:description xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:x="http://www.daisy.org/ns/xprocspec" xmlns:e="http://example.net/ns" script="../steps/identity.xpl">

<x:scenario label="running xprocspec test which refers to a non-existing port">
<x:call step="e:identity">
<x:option name="option.required" select="''"/>
<x:input port="source.document.primary">
<x:document type="inline">
<doc1 attr="value">
<child>text-content</child>
<child>mix<e>ed</e>content</child>
</doc1>
</x:document>
</x:input>
</x:call>

<x:context label="the primary input port">
<x:document type="port" port="source.document.primary"/>
</x:context>
<x:expect type="compare" label="Should be equal to input document ignoring ...">
<x:document type="inline">
<doc1 attr="value">
<child>...</child>
<child>mix<e>ed</e>content</child>
</doc1>
</x:document>
</x:expect>
<x:expect type="compare" label="Should be equal to input document ignoring mixed content with ...">
<x:document type="inline">
<doc1 attr="value">
<child>text-content</child>
<child>...</child>
</doc1>
</x:document>
</x:expect>
<x:expect type="compare" label="Should be equal to input document ignoring attributes with ...">
<x:document type="inline">
<doc1 attr="...">
<child>text-content</child>
<child>mix<e>ed</e>content</child>
</doc1>
</x:document>
</x:expect>
</x:scenario>

</x:description>