<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/select-with-xml-base-001.xml"
        name="select-with-xml-base-001.xml"
        expected="pass">
   <t:info>
      <t:title>select-with-xml-base-001</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2025-02-26</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Created test.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Test that selecting portions of a document and relative xml:base
    attributes are handled correctly.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:c="http://www.w3.org/ns/xproc-step"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      version="3.0">
         <p:output port="result"/>
         <p:xslt>
            <p:with-input port="source" select="/c:directory/c:directory">
               <c:directory xml:base="http://example.com/tmp/y/" name="y">
                  <c:file xml:base="file" name="file"/>
                  <c:directory xml:base="z/" name="z">
                     <c:file xml:base="file" name="file"/>
                  </c:directory>
               </c:directory>
            </p:with-input>
            <p:with-input port="stylesheet">
               <xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                               exclude-result-prefixes="xs"
                               version="3.0">
                  <xsl:template match="*">
                     <xsl:copy>
                        <xsl:copy-of select="@*"/>
                        <xsl:attribute name="b" select="base-uri(.)"/>
                        <xsl:apply-templates/>
                     </xsl:copy>
                  </xsl:template>
               </xsl:stylesheet>
            </p:with-input>
         </p:xslt>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://purl.oclc.org/dsdl/schematron"
                queryBinding="xslt2">
         <s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="c:directory">Root element is not 'c:directory'.</s:assert>
               <s:assert test="c:directory/@b = 'http://example.com/tmp/y/z/'">The base URI is incorrect.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="select-with-xml-base-001.xml">
      <c:directory xmlns:c="http://www.w3.org/ns/xproc-step"
                   xml:base="z/"
                   name="z"
                   b="http://example.com/tmp/y/z/">
         <c:file xml:base="file" name="file" b="http://example.com/tmp/y/z/file"/>
      </c:directory>
   </t:result>
</t:test>
