xPath query attributes in a list

Questions about XML that are not covered by the other forums should go here.
gg7aph
Posts: 5
Joined: Tue Feb 18, 2020 5:29 pm

xPath query attributes in a list

Post by gg7aph » Wed Jun 24, 2020 10:47 pm

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;")

adrian
Posts: 2659
Joined: Tue May 17, 2005 4:01 pm

Re: xPath query attributes in a list

Post by adrian » Thu Jun 25, 2020 5:09 pm

Hi,

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

Code: Select all

Input[@type='List']/List/ListItems//ListItem/@text
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

gg7aph
Posts: 5
Joined: Tue Feb 18, 2020 5:29 pm

Re: xPath query attributes in a list

Post by gg7aph » Mon Jul 06, 2020 8:48 pm

@adrian, Thanks for the info but I get the below error:
XML.png
XML.png (205.01 KiB) Viewed 234 times
Attachments
image.png
image.png (224.73 KiB) Viewed 234 times

adrian
Posts: 2659
Joined: Tue May 17, 2005 4:01 pm

Re: xPath query attributes in a list

Post by adrian » Tue Jul 07, 2020 8:53 am

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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply