D
Dirk McCormick
I need to transform something that looks like this
<!-- %%%%%%%%%%%%%%%%%%%%%%% -->
<MyStructure>
<Packages>
<Package>
<PkgBenefitCode>1</PkgBenefitCode>
<PkgBenefitCode>2</PkgBenefitCode>
<PkgBenefitCode>3</PkgBenefitCode>
</Package>
...
</Packages>
<Benefits>
<Benefit code="1">
<Content>The content 1</Content>
</Benefit>
<Benefit code="2">
<Link>http://www.example.com</Link>
</Benefit>
<Benefit code="3">
<Content>The content 3</Content>
</Benefit>
...
</Benefits>
</MyStructure>
<!-- %%%%%%%%%%%%%%%%%%%%%%% -->
Into an HTML table with rows having alternating background colours,
and containing only Content, ie ignoring the Benefits with a Link
element.
I do a for-each on the PkgBenefitCode elements and then I do an if
within the for-each to determine whether the Content element exists.
This means that I can't use test="position() mod 2" to determine the
background colour of the table row, because the if filters some
elements out and results in the background colours not always
alternating properly. See sample code below.
Can anyone suggest a way of solving this that's not too much of a
hack?
(eg using recursive method call with alternating parameter is a hack!)
Ideally what I need is to pass a filtered list to the foreach, or in
the foreach have a test for whether the Benefit element contains a
Link element but I can't see how to do this.
Sample code is below:
<table>
<xsl:for-each select="/MyStructure/Packages/Package/PkgBenefitCode">
<xsl:if test="count(/MyStructure/Benefits/Benefit[@code=string(.)]/Content)
= 1">
<tr><td bgColor="<!--position() mod 2-->">
<xsl:value-of select="/MyStructure/Benefits/Benefit[@code=string(.)]/Content"/>
</td></tr>
</xsl:if>
</xsl:for-each>
</table>
Any help appreciated.
Please post replies to newsgroup only.
Cheers,
Dirk
<!-- %%%%%%%%%%%%%%%%%%%%%%% -->
<MyStructure>
<Packages>
<Package>
<PkgBenefitCode>1</PkgBenefitCode>
<PkgBenefitCode>2</PkgBenefitCode>
<PkgBenefitCode>3</PkgBenefitCode>
</Package>
...
</Packages>
<Benefits>
<Benefit code="1">
<Content>The content 1</Content>
</Benefit>
<Benefit code="2">
<Link>http://www.example.com</Link>
</Benefit>
<Benefit code="3">
<Content>The content 3</Content>
</Benefit>
...
</Benefits>
</MyStructure>
<!-- %%%%%%%%%%%%%%%%%%%%%%% -->
Into an HTML table with rows having alternating background colours,
and containing only Content, ie ignoring the Benefits with a Link
element.
I do a for-each on the PkgBenefitCode elements and then I do an if
within the for-each to determine whether the Content element exists.
This means that I can't use test="position() mod 2" to determine the
background colour of the table row, because the if filters some
elements out and results in the background colours not always
alternating properly. See sample code below.
Can anyone suggest a way of solving this that's not too much of a
hack?
(eg using recursive method call with alternating parameter is a hack!)
Ideally what I need is to pass a filtered list to the foreach, or in
the foreach have a test for whether the Benefit element contains a
Link element but I can't see how to do this.
Sample code is below:
<table>
<xsl:for-each select="/MyStructure/Packages/Package/PkgBenefitCode">
<xsl:if test="count(/MyStructure/Benefits/Benefit[@code=string(.)]/Content)
= 1">
<tr><td bgColor="<!--position() mod 2-->">
<xsl:value-of select="/MyStructure/Benefits/Benefit[@code=string(.)]/Content"/>
</td></tr>
</xsl:if>
</xsl:for-each>
</table>
Any help appreciated.
Please post replies to newsgroup only.
Cheers,
Dirk