XPATH help for TextIndexed result

Post Reply
Arthur
Member
Posts: 114
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

XPATH help for TextIndexed result

Post by Arthur »

Dear XML / XPath specialists :)
I have an XML (which is the PitStop Server Preflight result), with a structure like this:

Code: Select all

<?xml version="1.0"?>
<PageBoxInfo name="TestFile.pdf" unit="mm" pageBoxesEqual="false">
  <Page index="1" rotate="0" scaling="1">
    <ArtBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <BleedBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <CropBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <MediaBox defined="true" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <TrimBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
  </Page>
  <Page index="2" rotate="0" scaling="1">
    <ArtBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <BleedBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <CropBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <MediaBox defined="true" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <TrimBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
  </Page>
  <Page index="3" rotate="0" scaling="1">
    <ArtBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <BleedBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <CropBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <MediaBox defined="true" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <TrimBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
  </Page>
  <Page index="4" rotate="0" scaling="1">
    <ArtBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <BleedBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <CropBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <MediaBox defined="true" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
    <TrimBox defined="false" width="210" height="297" minX="0" minY="0" maxX="210" maxY="297"/>
  </Page>
  <Page index="5" rotate="180" scaling="1">
    <ArtBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <BleedBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <CropBox defined="true" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <MediaBox defined="true" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <TrimBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
  </Page>
  <Page index="6" rotate="180" scaling="1">
    <ArtBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <BleedBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <CropBox defined="true" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <MediaBox defined="true" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
    <TrimBox defined="false" width="221.897" height="297.039" minX="0" minY="0" maxX="221.897" maxY="297.039"/>
  </Page>
</PageBoxInfo>
I am trying to define an XPath that would return a TextIndexed list of Page index results matching only the specified width (ideally rounded to 222mm in my desired case).

I was able to quickly set all the Page/@index which returns all the pages from this report in an Indexed list, by going:
[Metadata.TextIndexed:Path="/PageBoxInfo/Page/@index",Dataset="Log",Model="XML",Separator=","]

but what would be the path in this case to only show the ones that match the Mediabox[@width=221.897]

I started pulling my hair out and already getting less due to my age, so no good :)
Would anyone please help with this ??
mkayyyy
Member
Posts: 80
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: XPATH help for TextIndexed result

Post by mkayyyy »

Pretty sure this XPath will cover what you're wanting:

Code: Select all

//Page[./MediaBox/@width = 221.897]/@index
Arthur
Member
Posts: 114
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: XPATH help for TextIndexed result

Post by Arthur »

Thx mkayyyy.
Almost there, as it turns out not all pages were exactly 221.897, so need to round this to 222 to cover all the variations both up & down.
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

Re: XPATH help for TextIndexed result

Post by freddyp »

Code: Select all

//Page[round(./MediaBox/@width) = 222]/@index
Arthur
Member
Posts: 114
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: XPATH help for TextIndexed result

Post by Arthur »

Thx Freddy.
Got it working yesterday already, but thx for yours which confirms I got it right ;)
Post Reply