xsl-list
[Top] [All Lists]

Re: [xsl] Required item type of value of variable $images is element(); supplied value has item type text()

2019-03-31 14:28:17
That’s not how the as attribute is supposed to work. It serves as as a "treat as" assertion, not so much as a filter that drops nodes from a sequence.

You can filter out unwanted whitespace-only text nodes in at least 3 ways:

1. by declaring xsl:strip-space for certain contexts

2. by defining "empty" templates in ac:image mode that match text()[not(normalize-space())] in certain contexts

3. or by doing something like this:
<xsl:variable name="prelim" as="item()*">
  <xsl:apply-templates mode="ac:image"/>
</xsl:variable>
<xsl:variable name="images"as="element()*" select="$prelim/self::*"/>

Gerrit


On 31.03.2019 21:00, Martynas Jusevičius martynas(_at_)atomgraph(_dot_)com 
wrote:
Hi,

I have a simple snippet like this

         <xsl:variable name="images" as="element()*">
             <xsl:apply-templates mode="ac:image"/>
         </xsl:variable>

Sometimes the ac:image templates will return an <img> element,
sometimes nothing.

In the case where there are no elements in the variable, I get an error

     Required item type of value of variable $images is element();
supplied value has item type text()

When I output the text, it's just whitespace.

The element() cardinality is *, so why can't the processor just
suppress the whitespace and treat the variable content as zero
elements?

The processor is Saxon-CE BTW.

Martynas
atomgraph.com



--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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