[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
> 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=""
 <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
 <xsl:template match="lay:data">
  <xsl:variable name="CtrlExists">
    <xsl:when test="_Ctrl">
     <xsl:value-of select="'1'"/>
     <xsl:value-of select="'0'"/>
   <xsl:for-each select="rep:Rpt_Inven/rep:Invens">
     <_Col name="Entity">
      <xsl:if test="$CtrlExists='1'">
       <xsl:for-each select="rep:Inven/rep:Entity">
        <xsl:sort select="."/>
         <xsl:value-of select="."/>

is applied on your source.xml:

<data xmlns="urn:abcd:layers">
  <Rpt_Inven xmlns="urn:abcd:RepInven">
        <Entity> Ent1</Entity>
        <Entity> Ent2</Entity>
        <Entity> Ent3</Entity>
  <!-- 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">
      <_Col name="Entity"/>

the wanted result is produced:

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

The same happens if I use Saxon 6.5.3

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


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

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

Current Thread