Page 1 of 1

xPath query attributes in a list

Posted: Wed Jun 24, 2020 10:47 pm
by gg7aph
Hello, How would I get the @text attribute for each <ListItem> in the below?

Code: Select all

<Controls>
                    <Control id="108" defaultfieldname="purpose" controltype="Control1x2" styleid="0" readonly="False" required="False" skiponedit="False">
                      <Labels title="Purpose" description="purpose" />
                      <Input type="List" allowdecimals="False" formvalueproviderid="0">
                        <List serviceid="0" layerindex="0" fieldname="" multiselect="False">
                          <ListItems>
                            <ListItem text="Routine" value="Routine" />
                            <ListItem text="Dead End" value="Dead End" />
                            <ListItem text="Disinfection" value="Disinfection" />
                            <ListItem text="Water Quality" value="Water Quality" />
                            <ListItem text="System" value="System" />
                          </ListItems>
                        </List>
                      </Input>
                      <Value text="" textformatid="0" valueformatid="0" codedvaluedisplay="Name" />
                      <Targets />
                      <Dependencies />
                      <Validations />
                    </Control>
I can use the following xPath query to get as far as concatenating the title, defaultfieldname and type. If the type = list then it has child elements I need to include.

Code: Select all

string-join(//AssetLayers/AssetLayer/Forms//Control/(concat(Labels/@title, ',',@defaultfieldname,',', Input/@type,List)), "&#10;")

Re: xPath query attributes in a list

Posted: Thu Jun 25, 2020 5:09 pm
by adrian
Hi,

In the context of Control, instead of "Input/@type,List", use:

Code: Select all

Input[@type='List']/List/ListItems//ListItem/@text
Regards,
Adrian

Re: xPath query attributes in a list

Posted: Mon Jul 06, 2020 8:48 pm
by gg7aph
@adrian, Thanks for the info but I get the below error:
XML.png
XML.png (205.01 KiB) Viewed 2122 times

Re: xPath query attributes in a list

Posted: Tue Jul 07, 2020 8:53 am
by adrian
Hi,

Not sure what's the desired output. Comma separated?
You can use string-join() around the XPath that returns the sequence.
e.g.

Code: Select all

string-join(//Control/(concat(Labels/@title,  ',' ,@defaultfieldname, ',' , Input/@type, ',' ,string-join(Input[@type='List']/List/ListItems//ListItem/@text, ','))), "&#10;")
Regards,
Adrian