Re: [xsl] xpath help?

Subject: Re: [xsl] xpath help?
From: "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Feb 2025 15:08:26 -0000
Hey Dan,

Actually, you have (used the axes). Often people use XPath without knowing
that's what they are doing.

Every time you say 'div/h1' you are saying 'child::div/child::h1'.

'span/@class' is short for 'child::span/attribute::class'. Etc.

Search for "XPath abbreviations" - for example, I get this page back:

https://www.stylusstudio.com/docs/v2007/d_xpath95.html

There is also the XPath 1.0 Recommendation:

https://www.w3.org/TR/1999/REC-xpath-19991116/#path-abbrev

Cheers, Wendell

From: dvint dvint@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, February 12, 2025 7:29 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xpath help?

Thanks, I don't think I've ever seen an XPath example with parents before.
I've certainly never used them. This did fix the problem.

..thanks
..dan



Sent from my Verizon, Samsung Galaxy smartphone


-------- Original message --------
From: "David Carlisle d.p.carlisle@xxxxxxxxx<mailto:d.p.carlisle@xxxxxxxxx>"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>>
Date: 2/12/25 2:58 PM (GMT-08:00)
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [xsl] xpath help?

 you are selecting all elements that are the first child of their parent

use

(//a[contains(@filepath, 'preface.html')])[1]/@newid

or

/descendant::a[contains(@filepath, 'preface.html')][1]/@newid

David



On Wed, 12 Feb 2025 at 22:53, dvint@xxxxxxxxx<mailto:dvint@xxxxxxxxx>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>> wrote:
I have this xpath that returns more than one result

//a[contains(@filepath, 'preface.html')]/@newid

I thought adding [1] to it like this would get me the first entry, but
the result doesn't change

//a[contains(@filepath, 'preface.html')][1]/@newid

Here is an example of the file I'm processing


<nav>
        <div class="coverpage">
                <span class="publicationdate">February 12, 2025</span>
        </div>
        <div class="copyrightstatement"/>
        <div class="toc">
                <ul class="nav-list">
                        <li class="nav-item is-current-page" data-depth="1">
                                <a newid="d3e90" class="nav-link"
filepath="preface.html"
                                        href="#d3e90"
entry-type="file">Evaluation</a>
                        </li>
                        <li class="nav-item" data-depth="1">
                                <a newid="d3e139" class="nav-link"
                                        filepath="${release.notes.base}/prefa
ce.html" href="#d3e139"
                                        entry-type="URL">Release notes</a>
                        </li>
                        <li class="nav-item" data-depth="1">
                                <a newid="d3e237" class="nav-link"
                                        filepath="../deployment-planning-guid
e/preface.html"
                                        href="#d3e237"
entry-type="file">Deployment planning</a>
                        </li>
                        <li class="nav-item" data-depth="2">
                                <a newid="d3e247" class="nav-link"
                                        filepath="../deployment-planning-guid
e/understanding-iam.html"
                                        href="#d3e247"
entry-type="file">Identity and Access
                                        Management</a>
                        </li>
                        <li class="nav-item" data-depth="3">
                                <a newid="d3e255" class="nav-link"
                                        filepath="../deployment-planning-guid
e/not-just-sso.html"
                                        href="#d3e255" entry-type="file">More
than just single
                                        sign-on</a>
                        </li>
                </ul>
        </div>
</nav>

XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/1240222> (by
email)
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3302254> (by
email<>)

Current Thread