[xsl] xsltproc buggy compared to xalan

Subject: [xsl] xsltproc buggy compared to xalan
From: Roalt Aalmoes <aalmoes@xxxxxx>
Date: Tue, 27 Apr 2004 14:02:34 +0200
Hi All,

I'm new to the list and also pretty new to XSLT, so please forgive me if
I oversee something with the following problem:

I have two ways to convert an .xml to a another file using XSL, one via
a xalan-based java tool but the other one using xsltproc. In the
following case, it looks that xalan-java does the correct behavior,
while xsltproc fails at the first attempt, but succeeds when you do the
same thing twice. 

For me it looks like this is a serious bug in the xsltproc tool, but
because I'm quite new, I simply cannot be really sure.

The following xslt code goes wrong with xsltproc, but okay with my
xalan-java solution:

<xsl:template name="fh-type">
  <xsl:param name="type"/>
  <!-- scan the included -->
  <xsl:variable name="local">
    <xsl:apply-templates select="//narsim:types" mode="type">
      <xsl:with-param name="type" select="$type"/>
    </xsl:apply-templates>
  </xsl:variable>
  <xsl:variable name="remote">
    <xsl:if test="$local=''">
      <xsl:variable name="filename">../../svc/types.xml</xsl:variable>
      <!-- check the include files -->
      <xsl:for-each select="//narsim:includes/narsim:include">
        <xsl:variable name="documentname">
          <xsl:apply-templates select="document($filename)/narsim:index"
mode="ref-link">
            <xsl:with-param name="include" select="."/>
          </xsl:apply-templates>
        </xsl:variable>
        <xsl:variable name="documentXML"><xsl:value-of
select="$documentname"/>.xml</xsl:variable>
        <xsl:apply-templates
select="document($documentXML)/narsim:types" mode="type">
          <xsl:with-param name="type" select="$type"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:if>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$local=''">
      <xsl:value-of select="$remote"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$local"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


The first time you call it, in my data-set (.xml file), remote is ''
(empty) while running it with my java-xalan tool, it is actually filled.
However, if I pass through this the second time or I duplicate the
remote part, it also works with xsltproc. For instance the following
code does work:

<xsl:template name="fh-type">
  <xsl:param name="type"/>
  <!-- scan the included -->
  <xsl:variable name="local">
    <xsl:apply-templates select="//narsim:types" mode="type">
      <xsl:with-param name="type" select="$type"/>
    </xsl:apply-templates>
  </xsl:variable>
  <xsl:variable name="remote1">
    <xsl:if test="$local=''">
      <xsl:variable name="filename">../../svc/types.xml</xsl:variable>
      <!-- check the include files -->
      <xsl:for-each select="//narsim:includes/narsim:include">
        <xsl:variable name="documentname">
          <xsl:apply-templates select="document($filename)/narsim:index"
mode="ref-link">
            <xsl:with-param name="include" select="."/>
          </xsl:apply-templates>
        </xsl:variable>
        <xsl:variable name="documentXML"><xsl:value-of
select="$documentname"/>.xml</xsl:variable>
        <xsl:apply-templates
select="document($documentXML)/narsim:types" mode="type">
          <xsl:with-param name="type" select="$type"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:if>
  </xsl:variable>
  <!-- Duplicate previous code to check if it works around bug in
xsltproc -->
  <xsl:variable name="remote2">
    <xsl:if test="$local=''">
      <xsl:variable name="filename">../../svc/types.xml</xsl:variable>
      <!-- check the include files -->
      <xsl:for-each select="//narsim:includes/narsim:include">
        <xsl:variable name="documentname">
          <xsl:apply-templates select="document($filename)/narsim:index"
mode="ref-link">
            <xsl:with-param name="include" select="."/>
          </xsl:apply-templates>
        </xsl:variable>
        <xsl:variable name="documentXML"><xsl:value-of
select="$documentname"/>.xml</xsl:variable>
        <xsl:apply-templates
select="document($documentXML)/narsim:types" mode="type">
          <xsl:with-param name="type" select="$type"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:if>
  </xsl:variable>
  <!-- /Duplicate -->
  <xsl:choose>
    <xsl:when test="$local=''">
      <xsl:choose>
        <xsl:when test="$remote1=''">
          <xsl:value-of select="$remote2"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$remote1"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$local"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


Has anyone seen this strange behavior or do I actually do something
really weird here?

Kind regards,

Roalt

-- 
Roalt

Current Thread