Hi Richard,

This does look like a bug in Xalan-J.  However, you can avoid using the 
node-set extension function, if modify your stylesheet: slightly:

<xsl:stylesheet
  version="1.0"
  exclude-result-prefixes="bowman"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:bowman="http://www.bowmansystems.com";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

  <xsl:output method="xml" indent="yes"/>

  <bowman:state_abbrev_list>
     <state long="alabama">al</state>
     <state long="florida">fl</state>
     <state long="michigan">mi</state>
  </bowman:state_abbrev_list>

  <xsl:variable
    name="state_abbrev_list"
    select="document('')/xsl:stylesheet/bowman:state_abbrev_list" />
 
  <xsl:variable
    name="valid_states"
    select="$state_abbrev_list/state/@long |
            $state_abbrev_list/state" />

  <xsl:template match="/records">
    <xsl:for-each select="provider[state = $valid_states]">
      <provider><name><xsl:value-of select="name"/></name></provider>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

It might help you as a workaround for the problem, and is also more 
portable than relying on an extension function.

Dave





Richard Rowell <[EMAIL PROTECTED]>
10/08/2004 11:28 AM
 
        To:     xalan-j-users <[EMAIL PROTECTED]>
        cc:     (bcc: David N Bertoni/Cambridge/IBM)
        Subject:        Nodeset confusion

I'm using the nodeset extension and I'm seeing behavior I wasn't
expecting.  I create a variable by merging two nodesets created with the
extension.  I then have a template that checks for the existence of the
value of an element within the nodeset.  IE:

<xsl:stylesheet
version="1.0"
exclude-result-prefixes="xalan"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xalan="http://xml.apache.org/xalan";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
  <xsl:variable name="state_abbrev_list">
     <state long="alabama">al</state>
     <state long="florida">fl</state>
     <state long="michigan">mi</state>
  </xsl:variable>
  <xsl:variable name="valid_states"
select="xalan:nodeset($state_abbrev_list)/state/@long |
xalan:nodeset($state_abbrev_list)/state"/>
  <xsl:template match="/records">
        <xsl:for-each select="provider[state = $valid_states]">
            <provider><name><xsl:value-of
select="name"/></name></provider>
        </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

The problem is that it seems the iterator on the node set isn't being
reset on each iteration of the for-each correctly, as my results vary by
the order of the "states".  For example this XML file works fine and
prints both nodes as I would expect:
     <records>
       <provider>
            <name>Michigan</name>
            <state>mi</state>
        </provider>
        <provider>
            <name>Florida</name>
            <state>fl</state>
        </provider>
     </records>
However if you switch the order of the two nodes, make Florida come
first, then only Florida is printed.

Is this expected behavior or have I stumbled upon a "feature"?

I'm attaching the test case also.


-- 
Richard Rowell <[EMAIL PROTECTED]>

Attachment: nowork.xml
Description: Binary data

Attachment: test.xsl
Description: Binary data

Attachment: works.xml
Description: Binary data

Reply via email to