nw-xslt-002

Tests secondary result documents.

Test nw-xslt-002.xml is expected to pass.

It requires the following features: xslt-2.

The pipeline


<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" name="main" version="3.0">
  <p:output port="result"/>

  
  <p:xslt name="xslt">
    <p:with-input port="source">
<document xmlns="">
<primary>Primary</primary>
<secondary>Secondary 1</secondary>
<secondary>Secondary 2</secondary>
</document>
    </p:with-input>
    <p:with-input port="stylesheet">
      <p:inline expand-text="false">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xs" version="2.0">

<xsl:output xmlns:xsl="http://www.w3.org/1999/XSL/Transform" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>

<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform" match="secondary">
  <xsl:result-document xmlns:xsl="http://www.w3.org/1999/XSL/Transform" href="http://example.com/{count(preceding-sibling::secondary)+1}">
    <xsl:copy xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:apply-templates xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="@*,node()"/>
    </xsl:copy>
  </xsl:result-document>
</xsl:template>

<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform" match="element()">
  <xsl:copy xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:apply-templates xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="@*,node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform" match="attribute()|text()|comment()|processing-instruction()">
  <xsl:copy xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
</xsl:template>

</xsl:stylesheet>
      </p:inline>
    </p:with-input>
  </p:xslt>

  <p:for-each name="add-base">
    <p:with-input pipe="secondary"/>
    <p:add-attribute attribute-name="uri" attribute-value="{base-uri(.)}"/>
  </p:for-each>

  <p:wrap-sequence name="primary" wrapper="primary-document">
    <p:with-input pipe="@xslt"/>
  </p:wrap-sequence>

  <p:wrap-sequence name="secondary" wrapper="secondary-documents">
    <p:with-input pipe="@add-base"/>
  </p:wrap-sequence>

  <p:wrap-sequence wrapper="documents">
    <p:with-input>
      <p:pipe step="primary"/>
      <p:pipe step="secondary"/>
    </p:with-input>
  </p:wrap-sequence>
</p:declare-step>
  
MorganaXProc passing XML Calabash passing

Schematron validation


    <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:pattern>
        <s:rule context="/">
          <s:assert test="documents">The output root is not “documents”.</s:assert>
        </s:rule>
        <s:rule context="documents">
          <s:assert test="primary-document">There’s no “primary-document” element.</s:assert>
          <s:assert test="secondary-documents">There’s no “secondary-documents” element.</s:assert>
        </s:rule>
        <s:rule context="primary-document">
          <s:assert test="document">There’s no “document” element.</s:assert>
          <s:assert test="document/primary">There’s no “document/primary” element.</s:assert>
          <s:assert test="document/primary[.='Primary']">The “primary” element has the wrong content.</s:assert>
        </s:rule>
        <s:rule context="secondary-documents">
          <s:assert test="secondary">There’s no “secondary” element.</s:assert>
          <s:assert test="count(secondary)=2">There’s aren’t the right number of “secondary” elements.</s:assert>
          <s:assert test="(secondary[1] = 'Secondary 1' and secondary[2] = 'Secondary 2')                           or (secondary[1] = 'Secondary 2' and secondary[2] = 'Secondary 1')">The “secondary”
elements have the wrong content.</s:assert>
        </s:rule>
        <s:rule context="secondary">
          <s:assert test="(. = 'Secondary 1' and @uri='http://example.com/1')                           or (. = 'Secondary 2' and @uri='http://example.com/2')">The URIs are wrong.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  

Revision history

03 Aug 2019, Achim Berndzen

Added @features xslt-2

20 Jul 2019, Norman Walsh

Initial publication