How to create an xsl: function that returns a boolean

I want to create an xsl: function with several parameters that can return a boolean, I am having problems:

<xsl:if test="my:isEqual($Object1, $Object2)">SAME!</xsl:if>

<xsl:function name="my:isEqual">
    <xsl:param name="Object1" />
    <xsl:param name="Object2" />

    <xsl:variable name="Object1PostalCode select="$Object1/PostalCode" />
    <xsl:variable name="Object2PostalCode select="$Object2/PostalCode" />
    <xsl:if test="$Object1PostalCode = $Object2PostalCode">
        !!!What to do here!!!
    </xsl:if>
</xsl:function> 
+3
source share
2 answers

I want to create an xsl: function with several parameters that can return boolean, I have problems:

<xsl:function name="my:isEqual"> 

Your problems begin even here. As written, nothing guarantees that this function will not return any type or sequence of XDM elements.

. xsl:function . . . .

, : :

<xsl:function name="my:isEqual">           
  <xsl:param name="Object1" />           
  <xsl:param name="Object2" /> 

XSLT 2.0 :

<xsl:function name="my:isEqual" as="xs:boolean">           
  <xsl:param name="Object1" as="element()?" />           
  <xsl:param name="Object2" as="element()?" /> 

, :

    <xsl:if test="$Object1PostalCode = $Object2PostalCode">                     
      !!!What to do here!!!                 
    </xsl:if>             
</xsl:function>  

- true(), false():

    <xsl:sequence select="$Object1PostalCode eq $Object2PostalCode"/>                     
</xsl:function>
+8

<xsl:sequence select="$Object1PostalCode = $Object2PostalCode"/>

xsl:if.

+6

All Articles