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]>
<?xml version="1.0" encoding="UTF-8"?>
<records schema_revision="original"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sp.xsd">
<provider>
<name>Florida</name>
<state>fl</state>
</provider>
<provider>
<name>Michigan</name>
<state>mi</state>
</provider>
</records>
<?xml version="1.0"?>
<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:output method="xml" indent="yes"/>
<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">
<!-- this only pulls providers who have a valid state in either the physical or mailing address AND have a valid zip code AND have at provides at least one service code of type AIRS that does not start with a 'Y' -->
<xsl:for-each select="provider[state = $valid_states]">
<provider>
<name><xsl:value-of select="name"/></name>
</provider>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<records schema_revision="original"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sp.xsd">
<provider>
<name>Michigan</name>
<state>mi</state>
</provider>
<provider>
<name>Florida</name>
<state>fl</state>
</provider>
</records>