xsl-list
[Top] [All Lists]

RE: Using saxon:assign and testing content of variable

2005-09-20 20:24:43
You really ought to try and avoid using saxon:assign. There must be a better
way.

If saxon:assign has any content, then the resulting value will be a result
tree fragment (or temporary tree): that is, the variable will contain a
document node which may or may not have children. You probably want to test
whether it has children using test="$pageNumber/child::node()".

Setting a variable to an "empty" result tree fragment (a document node with
no children) is surprisingly difficult! It can be done using something like:

<xsl:variable name="var">
  <xsl:text/>
</xsl:variable>

basically, any xsl:variable instruction that has content, but whose content
is a no-op. You could also use

<xsl:variable name="var">
  <xsl:fallback/>
</xsl:variable>

or

<xsl:variable name="var">
  <xsl:if test="false()"/>
</xsl:variable>
  

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Dan Vint [mailto:dvint(_at_)dvint(_dot_)com] 
Sent: 20 September 2005 18:56
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Using saxon:assign and testing content of variable

I'm still working on my Index. Now I'm trying to gather the 
index terms up 
and group them and then generate the page numbers.

I'm using Saxon 6.5 and the group and item extensions to make 
this process 
reasonable. I've got the headings seeming to work properly up 
to 3 levels 
with see and see also support. Now I'm trying to gather up 
the page numbers 
with their markup and output them as a single statement once 
all the page 
numbers are gathered.

The process I wrote myself into has me collecting the page 
numbers in a 
variable that I can assign to with another saxon function.  
This was the 
template I had written:

<xsl:template name="page-sequence">
      <xsl:param name="NumberPage" select="false()" />

    <xsl:if test="$NumberPage">
         <xsl:choose>
                 <xsl:when test="$pageNumber=''">
                         <saxon:assign name="pageNumber">
                               <fo:leader leader-pattern="dots" 
leader-length="1in" />
                               <fo:basic-link 
internal-destination="{generate-id()}">
                                     <fo:page-number-citation 
ref-id="{generate-id()}" />
                                </fo:basic-link>
                          </saxon:assign>
                 </xsl:when>
                 <xsl:otherwise>
<!-- similar stuff here for continuation -->
                  </xsl:otherwise>
              </xsl:choose>
     </xsl:if>
</xsl:template>

As you see I'm assigning the <fo> markup to the variable and in the 
otherwise, I was adding additional page numbers with a comma 
separator.

What I'm at a loss for is the proper test in the <choice> to 
see if there 
is content in $pageNumber.

First what is the proper way to reset the variable to be empty and 
hopefully no nodes in the node-set? Does a simple <saxon:assign 
name="pageNumber"/> do it?

What is the best test to detect content in $pageNumber? I 
tried count() but 
it always returns 1, and the test for the empty string is not 
working either.

thanks
..dan

--------------------------------------------------------------
-------------
Danny Vint

Specializing in Panoramic Images of California and the West
http://www.dvint.com

voice: 510-522-4703


     



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--