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

Subject: Re: [xsl] Required item type of value of variable $images is element(); supplied value has item type text()
From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 31 Mar 2019 19:28:11 -0000
Thatbs 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 JuseviD ius martynas@xxxxxxxxxxxxx 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 GeschC$ftsfC<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.imsieke@xxxxxxxxx, http://www.le-tex.de

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

GeschC$ftsfC<hrer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt

Current Thread