Another XSLT question

topic posted Mon, February 2, 2004 - 10:48 PM by  Manny
Hello hello (= Yet again, I'm trying to transform an XML document trying to weed out certain nodes that satisfies certain conditions.

Say I have the following XML document:

<root>
<element attrib="value1">
<element attrib="value3"></element>
</element>

<element attrib="value2">
<element attrib="value4"></element>
<element attrib="value5"></element>
</element>

<do_not_show>
<hide>value3</hide>
<hide>value2</hide>
</do_not_show>
</root>


From above, I'm trying to hide the element whose attrib value equals to "value3" and whose is "value2" and thus also hide its child nodes: value4 and value5. However, it's also possible that <do_not_show> will not have any child nodes and thus will show all the elements.

What I have now that checks whether the element should be displayed or not is:

<xsl:for-each select="element[(/root/settings/disable and attribute::name != /root/settings/child::disable/text()) or (not(/root/settings/disable))]">
<!-- show elements here -->

</xsl:for-each>

The above condition works well if I don't have any <hide> elements or if I only have one <hide> element. The problem is when I have two or more <hide> elements then the parser displays ALL the elements. I'm pretty sure the answer is a simple one but my mind's going blank right now... H-E-L-P! :D

oh yeah. If possible, the solution I'm looking for only requires a modification in the condition statement in the <xsl:for-each> instead of doing a loop for each <element> then perform an <xsl:choose> whether the <hide> element is specified or not then perform another <xsl:for-each> to check if the current text() for <hide> matches the current value for @attrib (=
posted by:
Manny

Recent topics in "XML & XSLT"