[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: RE: [xsl] trouble looping using xsl:for-each and xsl:if
From: "Miller, Mark" <Mark.Miller@xxxxxxxxxxxxxxxx>
Date: Thu, 3 Dec 2009 15:39:13 -0500

Martin,

Your solution works perfectly!

Thanks for your help.

Mark J. Miller
MEADS International, Inc.


> -----Original Message-----
> From: Martin Honnen [mailto:Martin.Honnen@xxxxxx]
> Sent: Thursday, December 03, 2009 1:54 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] trouble looping using xsl:for-each and xsl:if
>
> 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/


Current Thread
Keywords
xsl