Subject: Re: [xsl] Each value in an XPath array is a sequence of elements... how to access a particular element in a particular array value? From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 6 Jun 2019 15:22:08 -0000 |
Firstly, I missed this, to select the first member in an array you need $groups?1 rather than $groups[1]. Secondly, if $rows is a sequence of row elements then $rows/row selects nothing because a row doesn't have a child::row. Thirdly, I'm not sure why you expect the 'Foo' row to be in the first group. distinct-values() loses order. Michael Kay Saxonica > On 6 Jun 2019, at 16:15, Costello, Roger L. costello@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Hi Michael, > > That XPath expression yields the empty set. > > I created these variables: > > <xsl:variable name="first-group" select="$groups[1]" /> > <xsl:variable name="Foo-row-first-group" select="($first-group?*)/row[Data eq 'Foo']"/> > > And then output the value of the second variable: > > <Foo-row-in-first-group> > <xsl:sequence select="$Foo-row-first-group" /> > </Foo-row-in-first-group> > > This is the output: > > <Foo-row-in-first-group/> > > Why does the XPath yield the empty set? Clearly the first group contains a <row> element with a <Data> element with value 'Foo'. Thoughts? > > /Roger > > > From: Michael Kay mike@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Thursday, June 6, 2019 10:47 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [EXT] Re: [xsl] Each value in an XPath array is a sequence of elements... how to access a particular element in a particular array value? > > $first_group is an array of nodes. To turn it into a sequence of nodes, use "?*". So it's > > ($first_group?*)/row > > (parentheses because I don't have the operator precedences in my head) > > Michael Kay > Saxonica > > > > > On 6 Jun 2019, at 15:26, Costello, Roger L. mailto:costello@xxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Hi Folks, > > This is an extension to a question that I had last week ... > > Recall that I want to group the <row> elements in the following XML. Each group should consist of those <row> elements that have the same ARPT__IDENT, TRM__IDENT values. > > <Test> > <row> > <ARPT__IDENT>A</ARPT__IDENT> > <TRM__IDENT>X</TRM__IDENT> > <Data>Foo</Data> > </row> > <row> > <ARPT__IDENT>A</ARPT__IDENT> > <TRM__IDENT>X</TRM__IDENT> > <Data>Bar</Data> > </row> > <row> > <ARPT__IDENT>A</ARPT__IDENT> > <TRM__IDENT>Y</TRM__IDENT> > <Data>Blah</Data> > </row> > <row> > <ARPT__IDENT>A</ARPT__IDENT> > <TRM__IDENT>Y</TRM__IDENT> > <Data>Plugh</Data> > </row> > </Test> > > That XML consists of two groups. Each group has two <row> elements. > > Martin provided a great XPath 3.1 expression for doing the grouping: > > <xsl:variable name="groups" as="array(element(row))*" select=" > let $keys := > distinct-values($rows/concat(ARPT__IDENT, '|', TRM__IDENT)) > return > for $i in $keys > return > array {$rows[$i = concat(ARPT__IDENT, '|', TRM__IDENT)] } > "/> > > In the following, I select the first group: > > <xsl:variable name="first-group" select="$groups[1]" /> > > Next, I want to select the <row> element in the first group that has Foo as the value of the <Data> element. I thought that this would be the appropriate XPath expression: > > <xsl:variable name="Foo-row-first-group" select="$first-group/row[Data eq 'Foo']"/> > > Apparently it is not the appropriate XPath expression, because I get this error message: > > Axis step child::element(Q{}row) cannot > be used here: the context item is not a node > > What is the appropriate XPath expression, please? > > /Roger > > http://www.mulberrytech.com/xsl/xsl-list > http://lists.mulberrytech.com/unsub/xsl-list/673357 ()
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Each value in an XPath ar, Martin Honnen martin | Thread | [xsl] XSD default attributes not wo, Graydon graydon@xxxx |
Re: [xsl] Each value in an XPath ar, Martin Honnen martin | Date | [xsl] XSD default attributes not wo, Graydon graydon@xxxx |
Month |