xsl-list
[Top] [All Lists]

Re: functions and sequences

2004-12-12 17:14:51
I've also run into this issue.

While it is perfectly understandable, it is a major change from
XSLT/XPath 1.0 where it was not allowed to have two immediate
text-node siblings.

Now we have sequences and we can have a sequence of text nodes.

I think it would be good to support the following in order to avoid
inconvenience and confusion:

   -  Allow an xs:string() constructor, which takes a sequence of
xs:strings or a sequence of text nodes; This will allow a function of
type xs:string to automatically convert a sequence of
strings/text-nodes to a single string return value.

   - Provide an overload of the concat() function, which takes a
single argument of type sequence of xs:string or sequence of text
nodes.


Cheers,
Dimitre.


On Mon, 13 Dec 2004 00:02:02 -0000, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:
<xsl:text> constructs a text node; if you have several <xsl:text> and/or
<xsl:value-of> instructions in your function, then the result of the
function is a sequence of text nodes. A sequence of text nodes can't be
automatically converted to a string.

One solution is to generate the output using XPath expressions instead:

<xsl:sequence select="
 if ($bibref/mods:relatedItem/@type = 'host')
 then concat('article-', $bibref/mods:relatedItem/mods:genre)
 else ....
"/>

Another solution is to wrap the various xsl:text and xsl:value-of
instructions in a containing <xsl:value-of>

<xsl:value-of>
 <xsl:choose>
   ...
 </xsl:choose>
</xsl:value-of>

This way the function returns a single text node, which is automatically
converted to a single string if the declared return type is xs:string.

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



-----Original Message-----
From: Bruce D'Arcus [mailto:bdarcus(_at_)myrealbox(_dot_)com]
Sent: 12 December 2004 23:09
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] functions and sequences

I've run across this issue in a different context, but can't
figure out
how to apply it here.

I have this function (within a large stylesheet).  It works if I
comment out the two lines indicated with the comments, but I get a "E
net.sf.saxon.xpath.DynamicError: A sequence of more than one item is
not allowed as the result of function bib:reftype()" error
otherwise.
Is there some way to get this to work?  I'm not really sure
how much of
the related code I need to show to have this make any sense!

   <xsl:function name="bib:reftype" as="xs:string">
     <xsl:param name="bibref" as="element(mods:mods)?"/>
     <xsl:choose>
       <xsl:when test="$bibref/mods:relatedItem/@type = 'host'">
         <xsl:variable name="issuance"
select="$bibref/mods:relatedItem/mods:originInfo/mods:issuance"/>
         <xsl:choose>
           <xsl:when test="bib:refclass($bibref) = 'part-inSerial'">
             <xsl:text>article</xsl:text>
             <!-- this code introduces a sequence error;
don't know why
-->
             <xsl:text>-</xsl:text>
             <xsl:value-of
select="$bibref/mods:relatedItem/mods:genre"/>
           </xsl:when>
           <xsl:when test="bib:refclass($bibref) =
'part-inMonograph'">
             <xsl:choose>
               <xsl:when test="$bibref/mods:genre">
                 <xsl:value-of select="$bibref/mods:genre"/>
               </xsl:when>
               <xsl:otherwise>
                 <xsl:text>chapter</xsl:text>
               </xsl:otherwise>
             </xsl:choose>
           </xsl:when>
           <xsl:otherwise>
             <xsl:value-of select="$bibref/mods:genre"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:when>
       <xsl:otherwise>book</xsl:otherwise>
     </xsl:choose>
   </xsl:function>


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>