Nice one - thanks. Looks like I was over complicating things!
Main Topics
Browse All TopicsHiya
I've got an XML file which looks as follows:
<PolicyExtension>
<bCharged>false</bCharged>
<lID>5</lID>
<sDesc>text</sDesc>
</PolicyExtension>
<PolicyExtension>
<bCharged>false</bCharged>
<lID>9</lID>
<sDesc>text</sDesc>
</PolicyExtension>
<PolicyExtension>
<bCharged>false</bCharged>
<lID>3</lID>
<sDesc>text</sDesc>
</PolicyExtension>
<PolicyExtension>
<bCharged>false</bCharged>
<lID>2</lID>
<sDesc>text</sDesc>
</PolicyExtension>
If an attribute exists with a lID of 9 then I need to write <additional_windscreen_cov
If this attribute does not exist then I need to write <additional_windscreen_cov
So far, my code looks like:
<xsl:for-each select="/PoliciesAtDate/Po
<xsl:choose>
<xsl:when test="lID = 9">
<additional_windscreen_cov
</xsl:when>
<xsl:otherwise>
<additional_windscreen_cov
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
This outputs
<additional_windscreen_cov
<additional_windscreen_cov
<additional_windscreen_cov
<additional_windscreen_cov
because it obviously writes out the XML for each PolicyExtension it reads. I only need it to output Y or N depending on whether lID 9 exists or not.
I did also try the following code as using variables seemed like the most obvious solution:
<xsl:variable name="sWindscreen">N</xsl:
<xsl:for-each select="/PoliciesAtDate/Po
<xsl:choose>
<xsl:when test="lID = 9">
<xsl:variable name="sWindscreen">Y</xsl:
</xsl:when>
</xsl:choose>
</xsl:for-each>
<additional_windscreen_cov
But, this gives an error that sWindscreen cannot be defined twice within the same template.
Please can anyone help?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: GertonePosted on 2007-10-15 at 09:33:12ID: 20079447
remove the for-each from the test cyAtDate/P olicy/Poli cyExtensio ns/PolicyE xtension/l ID = 9"> er>Y</addi tional_win dscreen_co ver> er>N</addi tional_win dscreen_co ver>
and use
<xsl:choose>
<xsl:when test="/PoliciesAtDate/Poli
<additional_windscreen_cov
</xsl:when>
<xsl:otherwise>
<additional_windscreen_cov
</xsl:otherwise>
</xsl:choose>
it will then only be printed once