Subject: Re: [xsl] How to store a sequence into an element ... and maintain the sequence inside the element? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 19 Jul 2020 19:56:49 -0000 |
Hi Folks,select="count($list)"/></xsl:message>
I created a sequence (1, 2, 3) as follows:
<xsl:variable name="list" select="(1, 2, 3)" as="xs:integer*" />
I checked that $list contains 3 integers:
<xsl:message>count($list) = <xsl:value-of
other elements:
Sure enough, the output shows that there are 3 items:
count($list) = 3
Next, I want to store that sequence of integers in an element, along with
select="count($document/List)"/></xsl:message>
<xsl:variable name="document" as="element(Document)"> <Document> <Greeting>My List</Greeting> <List><xsl:sequence select="$list" /></List> <Ending>The End</Ending> </Document> </xsl:variable>
Does the <List> element contain a sequence of 3 integers:
<xsl:message>count($document/List) = <xsl:value-of
Yikes! No it doesn't:
count($document/List) = 1
How to do what I want to do? That is, how to store the sequence of integers
in an element, along with other elements, such that I can pull the sequence out of the element and immediately operate on the sequence? If that can't be done, then what's the right way to do what I want to do?
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())
<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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to store a sequence into , Dr. Roger L Costello | Thread | Re: [xsl] How to store a sequence i, Mukul Gandhi gandhi. |
[xsl] How to store a sequence into , Dr. Roger L Costello | Date | Re: [xsl] How to store a sequence i, Dr. Roger L Costello |
Month |