Re: [xsl] Selecting elements from source document based on matches to a second document

Subject: Re: [xsl] Selecting elements from source document based on matches to a second document
From: "Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 6 Mar 2023 16:48:11 -0000
Thank you Liam, that approach has cut the execution time by about 75%. I'll
try Dr Kay's suggestion next and see if that saves any more (although we are
using Saxon and he kinda hinted that Saxon would have optimised this
already!)

 There's typically less than a dozen paths in the list, so O(nB2) is not too
frightening. If necessary I can impose an upper limit on the paths and ask the
user to drill down a level if it is exceeded.

cheers
T

-----Original Message-----
From: Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, March 6, 2023 6:37 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Selecting elements from source document based on matches to
a second document

On Mon, 2023-03-06 at 03:12 +0000, Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx
wrote:
>
>
> I would like to produce an output document which consists of a log
> containing all the log entries where at least one of the logentry
> paths matches a path in the checkpaths document, and where the paths
> for each output logentry are limited to the matching paths.

I'm thinking these are filesystem paths, not XPath expressions. So here's some
first thoughts:

So, given
<xsl:variable name-"paths-to-match" as="xs:string*"
  select="doc('checkpaths.xml')/checkpaths/path" />

you can use
/log/logentry[paths/path = $paths=to-match]

This is O(nB2) on the number of paths, so if you have a lot of paths in the
checkpaths document, you'll want to do something smarter probably, but this is
a start.

To get only the matching paths,

<xsl:apply-templates select="/log/logentry[paths/path = $paths=to- match]"/>

then have an identity template (assuming XSLT 2; in XSLT 3 use <xsl:mode
on-no-match="shallow-copy"/> instead), and a template <xsl:template
match="path">
  <xsl:if test=". = $paths-to-match">
    <xsl:copy-of select="." />
  </xsl:if>
</xsl:template/>


liam

--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text
Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org

Current Thread