Re: custom non-atomic steps?

On 30 July 2013 19:52, Norman Walsh wrote:
> Jostein Austvik Jacobsen writes:

  Hi,

>> Has custom non-atomic steps (steps where you can provide one or more
>> subpipelines upon invocation) been discussed as a possibility in
>> XProc v.Next? It would for instance allow us to define our own
>> custom syntactic sugar.

> I don't think it's been discussed. It's not clear how to describe a
> custom step in a standard way.

  If we are considering the "macro" approach, if we take the
initial example again:

    <my:if test="...">
       <my:xpath-context .../>
       [ sub-pipeline ]
    </my:if>

being equivalent to:

    <p:choose>
       <p:when test="...">
          <px:xpath-context .../>
          [ sub-pipeline ]
       </p:when>
       <p:otherwise>
          <p:identity/>
       </p:otherwise>
    </p:choose>

  What about the following?:

    <p:declare-macro type="my:if">
       <p:input  port="source" primary="true"/>
       <p:output port="result" primary="true"/>
       <p:xslt>
	  <p:input port="stylesheet">
	     <p:inline>
		<xsl:stylesheet version="2.0">
		   <xsl:template match="/my:if">
		      <a:choose>
			 <a:when>
			    <xsl:copy-of select="@*"/>
			    <xsl:apply-templates/>
			 </a:when>
			 <a:otherwise>
			    <a:identity/>
			 </a:otherwise>
		      </a:choose>
		   </xsl:template>
		   <xsl:template match="my:xpath-context">
		      <a:xpath-context>
			 <xsl:copy-of select="node()"/>
		      </a:xpath-context>
		   </xsl:template>
		   <xsl:template match="node()" priority="-1">
		      <xsl:message terminate="yes">
			 Unknown: <xsl:copy-of select="."/>
		      </xsl:message>
		   </xsl:template>
		</xsl:stylesheet>
	     </p:inline>
	  </p:input>
	  <p:input port="parameters">
	     <p:empty/>
	  </p:input>
       </p:xslt>
    </p:declare-macro>

  This defines a "step like", but which is evaluated at compile-
time (instead of at run-time), with the corresponding XML as input
(here the my:if element), and the result is inserted in the lexer
tree, replacing the initial "macro call".  Here the macro is just
a stylesheet transforming the my:if into corresponding p:choose
(actually in an alias namespace, here bound to "a:").

  Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

Received on Wednesday, 31 July 2013 16:15:46 UTC