Re: [xsl] replacing <!DOCTYPE> with <?xml-model?> in XSLT

Subject: Re: [xsl] replacing <!DOCTYPE> with <?xml-model?> in XSLT
From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Aug 2022 11:08:03 -0000
Hi Martin, Wendell,

So it turns out this was an RTFM question. Oxygen provides the following Saxon
extension functions (documented
here<https://www.oxygenxml.com/doc/versions/24.1/ug-editor/topics/custom_oper
ation_sample-x-tools.html#custom_operation_sample__using_saxon_extension_func
tions_to_allow_custom_r>):

get-content-after-root() - Returns the content after root as xs:string.
set-content-after-root(xs:string) - Updates the content that will be
serialized in the refactored document after the root node.
get-content-before-root() - Returns the content before root as xs:string.
set-content-before-root(xs:string) - Updates the content that will be
serialized in the refactored document after the root node.

These functions are in the following namespace:

http://www.oxygenxml.com/ns/xmlRefactoring/functions

In my stylesheet, I computed a top-level variable for the type of file I was
processing:

  <!-- compute correct URN for RelaxNG topic or map -->
  <xsl:variable name="urn">
    <xsl:choose>
      <xsl:when test="ends-with(base-uri(),
'.dita')">com:synopsys:docshell:snpsTopicShell.rng</xsl:when>
      <xsl:when test="ends-with(base-uri(),
'.ditamap')">urn:oasis:names:tc:dita:rng:bookmap.rng</xsl:when>
    </xsl:choose>
  </xsl:variable>

then applied it from the document node template in a comment per the
documentation:

  <!-- change DTD to RelaxNG -->
  <xsl:template match="/">
    <xsl:if test="$urn ne ''">
      <xsl:comment>
        <xsl:value-of select="xrf:set-content-before-root('&lt;?xml
version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>&#xa;&lt;?xml-model
href=&quot;' || $urn || '&quot;
schematypens=&quot;http://relaxng.org/ns/structure/1.0&quot;?>&#xa;')"/>
      </xsl:comment>
    </xsl:if>
    <xsl:apply-templates select="node()"/>
  </xsl:template>

and everything worked as intended.

Thanks to both of you for jumping in and educating me on how XSLT sees (or
doesnbt) stuff outside the root element, and to Radu Coravu from Syncro Soft
who pointed me to the documentation off-list!


  *   Chris

Current Thread