xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krobe...@mmm.com
Subject RE: Conditional assignment of tree frag to variable doesn't work.
Date Thu, 08 May 2003 18:45:00 GMT

There are no errors being thrown.

I'm trying to upgrade some xalan-1 code that worked to xalan 2.5.0. It
isn't clear to me how to change the code so it will work. The stylesheet is
coded:

  <xsl:template match="/">
    <xsl:variable name="SelectFilterX">
      <xsl:choose>
        <xsl:when test="$Filter=normalize-space
($OSHProfile/default_filter/filter/field[1])">
          <xsl:apply-templates select="$OSHProfile/default_filter/filter"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="$OSHProfile/quick_filters/*[field[1]
=$Filter]"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="SelectFilter" select="xalan:nodeset
($SelectFilterX)"/>

   .... A lot of code

     <xsl:if test="($SelectFilter/field[2]=0 or mmiFacilityCid/@ncid
=$SelectFilter/field[position()>2]/text())">
     ....
     </xsl:if>

The 'if test' always evaluates to false because the assignment to
SelectFilterX fails. Something has changed since xalan-1 that has broken
the conditional assignment via xsl:apply-templates. It is not clear to me
how to change the conditional assignment so it will work in 2.5.0.

I can't assign a variable a value inside the 'when / otherwise' tags with
the visibility required to use it later in the stylesheet, outside the when
/ otherwise scope. It's hard to imagine a viable programming language
(which is what xslt is) in which the assignment and visibility rules seem
to be in conflict. Seems to me that either the scoping rules or the 'assign
only once' rule should change or the notion of variable declaration should
be introduced.

To implement the if test without the conditional assignment would result in
a terribly complicated expression that I would rather not even think
about.... I'm thinking there must be something fundemental here that I'm
missing.

Is there a good book out there that would clear things up? I have a book;
but it was published in Dec 2000. I'm particularly confused with result
tree fragments and node sets.

Thanks in advance.

Keith...



                                                                                         
                                       
                      "Andrew Welch"                                                     
                                       
                      <AWelch@piper-grou       To:       <kroberts@mmm.com>     
                                                
                      p.com>                     <xalan-j-users@xml.apache.org> 
                                                
                                               cc:                                       
                                       
                      05/08/2003 11:23         Subject:  RE: Conditional assignment of tree
frag to variable doesn't work.       
                      AM                                                                 
                                       
                                                                                         
                                       
                                                                                         
                                       





Hi,

>From a quick look at this it looks as though you are trying to reassign a
variable (NewVar3) which of course in xslt isnt possible.  The processor
should throw an error as the outer NewVar3 is in scope within the
choose/when (I would have thought this is fixed??).  Once the choose/when
has finished the NewVar3 in scope is the outer one, so viewing its value
with the xsl:copy-of will always result in "Default Value".

Also, you are treating RTF's as node-sets so Im assuming you have already
converted them using the node-set() extension.

cheers
andrew

> -----Original Message-----
> From: kroberts@mmm.com [mailto:kroberts@mmm.com]
> Sent: 08 May 2003 17:53
> To: xalan-j-users@xml.apache.org
> Subject: Re: Conditional assignment of tree frag to variable doesn't
> work.
>
>
>
> The assignment to NewVar2 copies the selected value; however
> NewVar3 copies
> the 'Default value'. The conditional assignment doesn't work.
> I've tried it
> with the when test evaluating to both true and false and
> neither one works.
> There must be some xslt secret to making this work; but it
> seems to me that
> this should work. This is either a bug or this is a quirky solution.
>
>     <xsl:variable name="NewVar2" select="$OSHProfile/default_filter"/>
>
>     <xsl:variable name="NewVar3">Default value</xsl:variable>
>     <xsl:choose>
>       <xsl:when test="$Filter=normalize-space
> ($OSHProfile/default_filter/filter/field[1])">
>          when test is true
>         <xsl:variable name="NewVar3" select
> ="$OSHProfile/default_filter/filter"/>
>       </xsl:when>
>       <xsl:otherwise>
>          when test is false
>         <xsl:variable name="NewVar3" select
> ="$OSHProfile/quick_filters/*[field[1]=$Filter]"/>
>       </xsl:otherwise>
>     </xsl:choose>
>
>     <xsl:copy-of select="$NewVar2"/>
>     <xsl:copy-of select="$NewVar3"/>
>
>
>
>
>
>
>
>                       "Eoin Breathnach"
>
>
>                       <ebreathnach@www.eoinbrea       To:
>   kroberts@mmm.com
>
>                       thnach.com>
> xalan-j-users@xml.apache.org
>
>                                                       cc:
>
>
>                       05/08/2003 02:29 AM
> Subject:  Re: Conditional assignment of tree frag to variable
> doesn't work.
>
>
>
>
>
>
>
>
>
>
> How do I get taken off this mailing list?
>
> Regards,
>
> Eoin
>
> ---------- Original Message -----------
> From: kroberts@mmm.com
> To: xalan-j-users@xml.apache.org
> Sent: Wed, 7 May 2003 17:58:55 -0600
> Subject: Conditional assignment of tree frag to variable doesn't work.
>
> > This is probably a simple question; but I've tried several things
> > and don't seem to be getting anywhere with this issue. I cannot get
> > the assignment to the variable SelectFilterX to work.  I'm trying to
> > get some old xalan-1 code to work in xalan 2.5.0.
> >
> > <xsl:variable name="SelectFilterX">
> >       <xsl:choose>
> >         <xsl:when test="$Filter
> > =$OSHProfile/default_filter/filter/field[1]">
> >           <xsl:apply-templates select
> ="$OSHProfile/default_filter/filter"/>
> >         </xsl:when>
> >         <xsl:otherwise>
> >           <xsl:apply-templates select
> ="$OSHProfile/quick_filters/*[field[1]
> > =$Filter]"/>
> >         </xsl:otherwise>
> >       </xsl:choose>
> >     </xsl:variable>
> >
> >     <xsl:copy-of select="$SelectFilterX"/>
> >
> > This doesn't copy anything. I tried copying OSHProfile and it copied
> > fine. OSHProfile is set in Java as a document element.
> >
> > Keith...
> ------- End of Original Message -------
>
>
>
>
>
>
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.470 / Virus Database: 268 - Release Date: 08/04/2003
>
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.470 / Virus Database: 268 - Release Date: 08/04/2003






Mime
View raw message