Hi

 

I am investigating the feasibility of creating a schema-aware XSLT that continually check validation of the result tree to test for the correct insertion of an element.

 

For example, I have a recursive template that acts like a glorified ‘copy-of’. When I try to insert the element into the result tree I try to calculate the correct node name then test it in the tree.

 

At the moment all I am able to do is build up the tree, element by element, then create a variable for the current element and use a copy-of with a saxon:try to test if the result will be valid. The test returns true if it finds a global declaration in my schema, not if it is valid to insert a node with that name in to the result tree.

 

In my simplified example below, my if( saxon:try( $output, saxon:function( 'xslf:error', 1 ) ) ) then '' else '' returns true | false for the insertion of my $output in isolation, not as part of the result tree.

 

Any clue how I can check against the whole result tree?

 

  <xsl:template name="create-nodeset">

 

    <xsl:param name="ns"/>

 

    <xsl:for-each select="$ns">

 

      <xsl:variable name="nodename">

        <xsl:choose>

          <xsl:when test="self::section and $trail='document'">customnodename</xsl:when>

          <xsl:otherwise><xsl:value-of select="name(.)"/></xsl:otherwise>

        </xsl:choose>

      </xsl:variable>

 

      <saxon:assign name="glbNodeChk" select="1"/>

      <saxon:assign name="glbValdMsg"/>

 

      <xsl:variable name="output">

        <xsl:element name="{$nodename}" validation="strict"/>

      </xsl:variable>

 

      <xsl:copy-of select="if( saxon:try( $output, saxon:function( 'xslf:error', 1 ) ) ) then ''  else ''"/>

 

      <xsl:if test="$glbNodeChk=1">

 

        <xsl:element name="{$nodename}">

 

          <!-- <xsl:copy-of select="@*"/> -->

 

          <xsl:for-each select="child::* | processing-instruction() | text()">

            <xsl:choose>

 

              <xsl:when test="self::processing-instruction()"><xsl:copy-of select="."/></xsl:when>

 

              <xsl:when test="self::text()"><xsl:value-of select="translate( .,'&#x0A;',' ')"/></xsl:when>

 

              <xsl:when test="self::node()">

                <xsl:call-template name="create-nodeset">

                  <xsl:with-param name="ns" select="current()"/>

                </xsl:call-template>

              </xsl:when>

 

            </xsl:choose>

          </xsl:for-each>

        </xsl:element>

      </xsl:if>

    </xsl:for-each>

  </xsl:template>

 

  <xsl:function name="xslf:error">

    <xsl:param name="error"/>

    <saxon:assign name="glbNodeChk" select="0"/>

    <saxon:assign name="glbValdMsg" select="$error"/>

  </xsl:function>

 

 

Many thanks, Lewis Marshall