[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Seek an XPath 2.0 expression for checking that eac

Subject: Re: Seek an XPath 2.0 expression for checking that each object in a file system has one parent
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 Oct 2016 23:10:03 -0000
Re:  Seek an XPath 2.0 expression for checking that eac
> On 16 Oct 2016, at 23:32, Costello, Roger L. costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Folks,
>
> I am modeling a file system. Below is a sample instance. D1 means Directory
1, F1 means File 1, etc. The instance says this: the content of directory 1 is
directory 2 and file 1. The content of directory 2 is file 2. Stated another
way, directory 2 and file 1 are contained in directory 1, and file 2 is
contained in directory 2.
>
> <Root>
>    <D1>
>        <D2/>
>        <F1/>
>    </D1>
>    <D2>
>        <F2/>
>    </D2>
> </Root>
>
> I want an XPath 2.0 expression which returns true if each object has one
parent. An "object" is a directory or a file. In the example above each object
has one parent, so the XPath should return true. Below is an illegal file
system because F1 has two parents: D1 and D2.

Surely in the one above, D2 has two parents, D1 and Root?

I'm actually confused as to whether F1, D1 etc are files and directories, or
whether they are file and directory names. If F1 appears in two places, does
that mean that the same file appears in two directories, or does it mean that
there are two files in two different directories that have the same name?

>
> <Root>
>    <D1>
>        <D2/>
>        <F1/>
>    </D1>
>    <D2>
>        <F2/>
>        <F1/>
>    </D2>
> </Root>
>
> The XPath should return false.
>
> This XPath is almost correct:
>
> for $i in /Root/* return for $j in $i/* return not(name($j) =
$i/following-sibling::*/*/name())
>
> I say it is "almost" correct because it returns multiple Booleans, not a
single Boolean result.

It only seems to cater for two levels of directory structure. You haven't
stated such a constraint in your requirements.
>
> Two Questions:
>
> 1. What is the correct XPath expression?

Hard to tell because the requirements aren't clear. For example is

<D1>
  <F1/>
  <F1/>
</D1>

valid or not?

> 2. Is there a different way to model in XML a file system that would enable
a simple XPath expression?
>

It rather depends on the file system you are modelling.

Michael Kay
Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.