SourceForge has been redesigned. Learn more.
Close

forcing strongly typed variables

2010-06-18
2012-10-08
  • Andriy Gerasika

    Andriy Gerasika - 2010-06-18

    Hello, Michael,
    Would it be reasonable to add something like saxon:force-type="yes" to
    xsl:stylesheet element? -- it would signal an error when "as" is missed on
    xsl:variable, xsl:param or xsl:function declarations inside the
    xsl:stylesheet.

    I am willing to enhance my XSLT code w/ strongly typed variables, hoping it
    will help to catch bugs more quickly.

    Thank You
    Kind Regards,
    Andriy Gerasika

     
  • Andriy Gerasika

    Andriy Gerasika - 2010-06-18

    p.s.
    Can you please suggest me the the correct "as" value for:
    <xsl:variable name="var1">
    <xsl:copy-of select="elm1"/>
    </xsl:variable>
    if I put as="element()*" it does not seem to work like it did before

     
  • Michael Kay

    Michael Kay - 2010-06-18

    This is a case where as="" does not merely declare the expected type, it
    changes the behaviour from the XSLT 1.0 "result tree fragment" behaviour,
    which implicitly creates a document node. The expansion of this is:

    <xsl:variable name="x" as="document-node()">
    <xsl:document>
    <xsl:copy-of ...=""/>
    </xsl:document>
    </xsl:variable>

    However, are you sure you really need to copy the node? Won't working with the
    original node work just as well? In which case you can use <xsl:variable name="var1" select="elm1"/>

    Please note that this is an XSLT coding question, nothing specific to Saxon,
    so it would be best asked on a general XSLT forum such as the xsl-list at
    mulberrytech.com

     

Log in to post a comment.