Re: [xsl] How to store a sequence into an element ... and maintain the sequence inside the element?

Subject: Re: [xsl] How to store a sequence into an element ... and maintain the sequence inside the element?
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Jul 2020 07:14:42 -0000
I think that, using a schema (for input & output documents) for an XSLT
transformation, in general is very useful. The main benefit is, I think,
stronger type checking of XML input/output data, which reveals many error
early during an XSLT transformation cycle.

On Mon, Jul 20, 2020 at 1:26 AM Martin Honnen martin.honnen@xxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> That expression will always return the number of "List" elements. If you
> use a schema and give that element a list datatype then I think that
> with schema-aware processing
>    $document/List/data()
> would give you a list and you could of course count that list with e.g.
>    count($document/List/data())
>
>
> So the simplest example would be
>
>      <xsl:import-schema>
>          <xs:schema>
>              <xs:element name="List" type="int-list"/>
>              <xs:simpleType name="int-list">
>                  <xs:list itemType="xs:integer"/>
>              </xs:simpleType>
>          </xs:schema>
>      </xsl:import-schema>
>
>      <xsl:template match="/" name="xsl:initial-template">
>          <xsl:variable name="list" select="(1, 2, 3)" as="xs:integer*" />
>          <xsl:message>count($list) = <xsl:value-of
> select="count($list)"/></xsl:message>
>          <xsl:variable name="list-element" as="schema-element(List)">
>              <List xsl:validation="strict">
>                <xsl:sequence select="$list"/>
>              </List>
>          </xsl:variable>
>          <xsl:message>count($list-element) = <xsl:value-of
> select="count($list-element)"/></xsl:message>
>          <xsl:message>count($list-element/data()) = <xsl:value-of
> select="count($list-element/data())"/></xsl:message>
>          <xsl:message select="$list-element instance of
> schema-element(List)"/>
>      </xsl:template>
>
> you would need to write a more complex schema for the more complex
> sample you had I think, I am not sure whether you could use a schema
> type for that element inside other untyped elements.
>




-- 
Regards,
Mukul Gandhi

Current Thread