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 23:00:58 GMT

Ok, I've done some more testing. I was able to get the conditional
assigment to work. Must have been a tester issue.... Sorry about that...

Let me review with you what I've discovered and perhaps you can help me
understand some things....

This code fragment:

    <xsl:variable name="defaultFilter" select
="$OSHProfile/default_filter/filter"/>
    <xsl:text>

Default Filter
    </xsl:text>
    <xsl:copy-of select="$defaultFilter"/>

Produces this output:

Default Filter
    <filter name="filter">

<field>
                Summary View
            </field>

<field>
                0
            </field>

<field>

</field>

</filter>

No problem here, this is what I would expect to see. The document element
is passed through from Java without any issue.

The problem comes in when a fragment of OSHProfile is assigned to
SelectFilterX.

Consider the following code fragment....

    <xsl:variable name="SelectFilterX">
      <xsl:choose>
        <xsl:when test="$Filter=normalize-space($fieldTest)">
          <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:text>

Select Filter X
    </xsl:text>
    <xsl:copy-of select="$SelectFilterX"/>
    <xsl:if test="normalize-space($SelectFilterX)='Summary View 0'">
        <xsl:text>Select Filter X is a string.</xsl:text>
    </xsl:if>
    <xsl:copy-of select="normalize-space($SelectFilterX)"/>

This produces this output:

Select Filter X


                Summary View


                0



        Select Filter X is a string.Summary View 0

The assignment to SelectFilterX didn't seem to maintain the RTF; but rather
now it is a string (no structure).

Consider this code:

    <xsl:variable name="SelectFilter" select="xalan:nodeset
($SelectFilterX)"/>
    <xsl:text>

Select Filter
    </xsl:text>
    <xsl:copy-of select="$SelectFilter"/>
    <xsl:copy-of select="normalize-space($SelectFilter)"/>

    <xsl:if test="normalize-space($SelectFilter)='Summary View 0'">
        <xsl:text>We have a whatever at this point.</xsl:text>
    </xsl:if>

This produces:

Select Filter


                Summary View


                0



        Summary View 0We have a whatever at this point.

This is the same essential result as SelectFilterX. My understanding was
that SelectFilterX is an RTF and SelectFilter is a NodeList and they are
handled differently in the stylesheet. In what ways are SelectFilterX and
SelectFilter different in terms of how they should be used in a stylesheet?

What happened to the structure of SelectFilterX and SelectFilter? My
understanding is that OSHProfile is an RTF and an assignment of an RTF to a
variable results in a copy of the RTF. This doesn't seem to be the case. I
have to test the var as I would a string.

Is this the way it is supposed to work now? If so, I've got a whole lot of
work to do....  aaarrrrgggg....

Looks like I'll have to define variables for each string value of interest
and use them in the conditional tests later in the stylesheet.

Keith...






                                                                                         
                                       
                      david_marston@us.i                                                 
                                       
                      bm.com                   To:       xalan-j-users@xml.apache.org    
                                       
                                               cc:                                       
                                       
                      05/08/2003 01:20         Subject:  RE: Conditional assignment of tree
frag to variable doesn't work.       
                      PM                                                                 
                                       
                                                                                         
                                       
                                                                                         
                                       




The construct
<xsl:variable name="foo">
  <xsl:choose>
    <xsl:when test="whatever">
      <xsl:text>We have a whatever at this point.</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>We don't have a whatever at this point.</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>
is part of our test suite, and it should work in all 2.x versions. Since
it creates an RTF, the variable is always "set", so a test for set-ness,
<xsl:when test="$foo != ''">
should always pass.

On the other hand, variables don't seem to pop out of xsl:choose as in
<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="whatever">
      <xsl:variable name="foo" select="'have-whatever'">
etc.
due to the visibility rule (following siblings and descendants) in part
11.5 of the XSLT spec. Sorry about that.

I think Keith's problem might be about critical values being buried in
the RTF he created. My suggestion is to have a variable that is set to a
simple boolean (not RTF) that will be directly usable in later xsl:when
elements. <xsl:when test="$have-whatever">
.................David Marston





Mime
View raw message