Why not use a boolean variable? Instead of
<xsl:variable name="CtrlExists">
<xsl:choose>
<xsl:when test="_Ctrl">
<xsl:value-of select="'1'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'0'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
write
<xsl:variable name="CtrlExists" select="boolean(_Ctrl)"/>
Having said that, I can't see at first glance why your code isn't
working.
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Murali Korrapati
Sent: 22 October 2003 02:24
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] checking for a node in the ancestor axis
Hi,
I have a situation here, where I have to check for the
node in the ancestor axis. I tried setting a flag depending
upon _Ctrl node into a xsl:variable and checking
for that variable later. But it doesn't seem like working.
<xsl:if test="$CtrlExists='1'"> in the following code
is always turning out false
But I can't do <xsl:if test="../../_Ctrl">, b'cos my xml
inside <Rpt_Inven> varies all the time.
I am sure there is a better way to do this. But I couldn't
get to it. Is there any proper way to do this.
Thanks a lot.
my xml:
<data xmlns="urn:abcd:layers">
<Rpt_Inven xmlns="urn:abcd:RepInven">
<Invens>
<Inven>
<Entity>Ent1</Entity>
</Inven>
<Inven>
<Entity>Ent2</Entity>
</Inven>
<Inven>
<Entity>Ent3</Entity>
</Inven>
</Invens>
</Rpt_Inven>
<!-- This node is optional. Doesn't exists all the time -->
<_Ctrl xmlns="" xmlns:lay="urn:abcd:layers"
xmlns:rep="urn:abcd:RepInven" xmlns:obj="urn:abcd:objects">
<_Table>
<_Col name="Entity"/>
</_Table>
</_Ctrl>
</data>
my xsl:
<xsl:stylesheet version="1.0" xmlns=""
xmlns:lay="urn:abcd:layers" xmlns:rep="urn:abcd:RepInven"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="lay:data">
<xsl:variable name="CtrlExists">
<xsl:choose>
<xsl:when test="_Ctrl">
<xsl:value-of select="'1'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'0'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<_Ctrl>
<xsl:for-each select="rep:Rpt_Inven/rep:Invens">
<_Table>
<_Col name="Entity">
<xsl:if
test="$CtrlExists='1'">
<xsl:for-each select="rep:Inven/rep:Entity">
<xsl:sort select="."/>
<_Item>
<xsl:value-of select="."/>
</_Item>
</xsl:for-each>
</xsl:if>
</_Col>
</_Table>
</xsl:for-each>
</_Ctrl>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list