[xsl] Re: checking for a node in the ancestor axis

Subject: [xsl] Re: checking for a node in the ancestor axis
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 22 Oct 2003 06:54:40 +0200
"Murali Korrapati" <murali.korrapati@xxxxxxxxx> wrote in message
news:D856C70D80A2394F990DCDBF52F6E6CB02F523@xxxxxxxxxxxxxxxxxxxxx
> 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
>

I cant't reproduce the reported behaviour -- your example works correctly
under MSXML4.

When your transformation:

<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" indent="yes"/>
 <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>


is applied on your source.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>

the wanted result is produced:

<?xml version="1.0" encoding="UTF-8"?>
<_Ctrl xmlns:lay="urn:abcd:layers" xmlns:rep="urn:abcd:RepInven">
   <_Table>
      <_Col name="Entity">
         <_Item> Ent1</_Item>
         <_Item> Ent2</_Item>
         <_Item> Ent3</_Item>
      </_Col>
   </_Table>
</_Ctrl>

The same happens if I use Saxon 6.5.3


Which XSLT processor are you using? Probably this is a bug.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread