xsl-list
[Top] [All Lists]

Re: [xsl] trouble looping using xsl:for-each and xsl:if

2009-12-03 13:54:15
Miller, Mark wrote:
I have gone round and round on this problem and seem to be getting
nowhere.
What do I have to change in my xsl file to get the desired output.  I
know I am close, but cannot see the forest for the trees.
It seems like my xsl:if statements are being ignored after the first one
executes.  I do not understand why the first cell in correct and the
last cell is correct but all the in-between cells are in error.

The xsl:if does not change the context node so you will need to select the relationship you are interested in into a variable and then use that variable to populate your table cells:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" indent="yes" encoding="iso-8859-1"/>
<xsl:template match="ematrix">
<html>
<body>
  <table border='1'>
  <tr>
    <th>Name</th>
    <th>B</th>
    <th>C</th>
    <th>L</th>
  </tr>
  <xsl:for-each select="businessObject">
  <xsl:sort select="objectName"/>
    <tr>
      <td nowrap='nowrap'><xsl:value-of select="objectName"/></td>
      <td>
        <xsl:variable name="rs"
select="fromRelationshipList/relationship[relationshipDefRef = 'Subordinate Submittal' and attributeList/attribute[name='Responsible IPT']/string = 'BMC4I']"/>
        <xsl:if
test="$rs">
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Due Customer']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Promise Date']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Submitted Date']/datetime,1,10)"/></p>
        </xsl:if>
      </td>
      <td>
        <xsl:variable name="rs"
select="fromRelationshipList/relationship[relationshipDefRef = 'Subordinate Submittal' and attributeList/attribute[name='Responsible IPT']/string = 'CMR']"/>
        <xsl:if
test="$rs">
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Due Customer']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Promise Date']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Submitted Date']/datetime,1,10)"/></p>
        </xsl:if>
      </td>
      <td>
        <xsl:variable name="rs"
select="fromRelationshipList/relationship[relationshipDefRef ='Subordinate Submittal' and attributeList/attribute[name='Responsible IPT']/string = 'LAUNCHER']"/>
        <xsl:if
test="$rs">
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Due Customer']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Promise Date']/datetime,1,10)"/></p>
          <p><xsl:value-of
select="substring($rs/attributeList/attribute[name='Submitted Date']/datetime,1,10)"/></p>
         </xsl:if>
      </td>
    </tr>
    </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>