XSLT Macros

Igor
2006-05-23
2012-10-08
  • Igor
    Igor
    2006-05-23

    Before delving into the XSLT2.0 specification I was hoping to see some
    form macro definition added to the specification.

    Even though Named Templates and functions are supported it would be
    nice to be able to create new instruction elements in XSLT. So instead of
    invoking the rather verbose

    <xsl:call-template name="doSomething">
    <xsl:with-param name="arg1">1</xsl:with-param>
    <xsl:with-param name="arg2">2</xsl:with-param>
    </xsl:call-template>

    It would be nice to define a macro that could be invoked as an XSLT
    instruction, for instance:

    <ns:doSomething arg1="1" arg2="2"/>

    Or go even further and define macros that accepts nested macros, etc.
    (see FreeMarker for some ideas)

    Any ideas as to how such a generic macro could be built on top of Saxon
    as XSLT2.0 does not seem to support it?

     
    • Igor
      Igor
      2006-05-25

      Is this even possible to be implemented as a generic extension instruction in Saxon?

      I dont have much experience with writing extension elements, but I would be willing to give it a shot and possibly even contribute that back to Saxon, if there is an interest.

       
      • Michael Kay
        Michael Kay
        2006-05-25

        If you're interested in doing this, I would think the most promising route is a preprocessor, which translates the "macros" (extension instructions) into named template calls. I think you could write this in XSLT.

         
    • Michael Kay
      Michael Kay
      2006-05-24

      I was thinking of doing this a while ago before we had stylesheet functions. It would be nice in some ways, but it's not clear to me that there's room for yet another mechanism alongside templates and functions, especially if it's not part of the language spec. On the other hand, xsl:function came originally from saxon:function, which was provided as a way of writing extension functions in XSLT, and one could argue that there's just as good a case for being able to write extension instructions in XSLT.