Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

<oXygen/> general issues.
stutzmann
Posts: 15
Joined: Fri Mar 29, 2019 12:25 am

Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by stutzmann » Wed Jan 27, 2021 5:47 pm

Hello everyone!

After a long time without question, here I am again. Thank you so much for all the help that you have already provided to me and others! The present question stems from the same needs as topic19849.html. The problem was solved as suggested by Sorin with AuthorOperation, which I did and it worked perfectly. Again, congratulations for the insights and explanations you can provide :D

In my actual environment, I am working in a large file with several sections. At the top of the file, there is an <include/> element (<include xmlns="http://www.w3.org/2001/XInclude" href="biblio.xml"/>.

In this environment, several Author Mode Operations allow
(1) to insert a <bibl/> element,
(2) add a @sameAs attribute with value provided with ${ask},
(3) retrieve all references xml:ids for references containing the value in the reference list "biblio.xml",
(4) displaying the references and selecting the one that is needed.

Operation (3) is based on ChangeAttributeOperation with following value:

Code: Select all

${xpath_eval(//biblStruct[contains(., "${xpath_eval(./@sameAs)}")]/concat("#", @xml:id))}
Now, I have divided the large initial file into smaller ones. Instead of including the reference list with <include/> in each of the smaller files, I would like to retrieve reference ids from an independent file. I have tried three methods, but failed and I do not know if my syntax is incorrect or if I have an issue with the "document()" function.


Option A: URL and authorizations
I have tried several paramaters, with double and simple quotes and additional ${xpath_eval) for the document() function, but I cannot find how to call the external document based on a parameter like the following one:

Code: Select all

${xpath_eval(document(https://gestion-projets.irht.cnrs.fr/svn/st-omer/sources/catalogues/notices/biblio.xml)//biblStruct[contains(., "${xpath_eval(./@sameAs)}")]/concat("#", @xml:id))}
On the top of that, the SVN is protected by login/password. Is it possible to include these within the xpath_eval function?

Option B: ${cfdu}
The same in trying to call the document directly in the folder with the ${cfdu} parameter

Code: Select all

${xpath_eval(document(${xpath_eval(concat(${cfdu}, "/biblio.xml"))})//biblStruct[contains(., "${xpath_eval(./@sameAs)}")]/concat("#", @xml:id))}
Is it an issue with quotes or with document() function?

Option C : parent folder
Is it possible to point to the parent folder, either with "../${cfdu}" or with a substring-before function like, in this case

Code: Select all

document(concat(substring-before('${cfdu}', '/notices'), '/biblio.xml'))
(and then the same $xpath_eval as in Option B.

Is there a way forward? Hope this is clear and within the scope. Thank you again so much for your support,
Dominique

stutzmann
Posts: 15
Joined: Fri Mar 29, 2019 12:25 am

Re: Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by stutzmann » Sat Jan 30, 2021 9:52 pm

Hi,

I was able to create a workaround with Author Mode Operation XSLTOperation and am sharing it here.

Source, Target: empty
Script below, solving the issue for options B and C (relative URL), otherwise just use the absolute URL in the variable "path-biblio".

Now, I have the same issue with ${xpath_eval} and document() function for my 4th operation. So, if anyone can provide help, that would still be useful :-)

Cheers,
DS

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:oxy="http://www.oxygenxml.com/ns/author/xpath-extension-functions" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tei="http://www.tei-c.org/ns/1.0"
    exclude-result-prefixes="xs oxy" version="2.0">
    
    <!--  <xsl:template match="/">
        <!-\- 
          sourceLocation parameter was set to /* to have a larger context.
          We can pinpoint the element that contained the caret 
          using the oxy:current-element() function.
      -\->
        <xsl:apply-templates select="oxy:current-element()"/>
    </xsl:template>-->
    
    <xsl:template match="tei:bibl">
        <xsl:variable name="sameAs" select="@sameAs"/>
        <xsl:variable name="base-uri" select="base-uri()"/>
        <xsl:variable name="path-biblio" select="concat(substring-before($base-uri, 'tei_'), 'biblio.xml')"/>
        <!-- Because the sourceLocation parameter was set to /* we now have access to 
         the root element and its attributes. -->
        <xsl:copy>
            <xsl:attribute name="sameAs" select="document($path-biblio)//tei:biblStruct[contains(., $sameAs)]/concat('#', @xml:id)"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <!-- This copy template will handle the contents of the list items. -->
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template> 
</xsl:stylesheet>

sorin_carbunaru
Posts: 384
Joined: Mon May 09, 2016 9:37 am

Re: Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by sorin_carbunaru » Tue Feb 02, 2021 11:52 am

Hi Dominique,

Can you make it clear where exactly the problem resides? Perhaps show me the troublesome code. It's quite a lot of information on this thread and I am getting lost into it :oops:.

What I understood is that you have problems with document() and $xpath_eval... If you check the value of the $xpath_eval, is it what you expect it to be? And if you provide that value directly to the document() function, is your script working fine?

Best wishes,
Sorin Carbunaru

stutzmann
Posts: 15
Joined: Fri Mar 29, 2019 12:25 am

Re: Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by stutzmann » Tue Feb 02, 2021 4:47 pm

Hi Sorin,

thank you for your question. To simplify, the command $xpath_eval(document()) apparently stops the process with or without quotes

Code: Select all

${xpath_eval(document(C:\Users\stutzmann\Documents\saint-omer\st-omer\sources\catalogues\notices\biblio-saint-omer.xml))}

Code: Select all

${xpath_eval(document('C:\Users\stutzmann\Documents\saint-omer\st-omer\sources\catalogues\notices\biblio-saint-omer.xml'))}

Code: Select all

${xpath_eval(document("C:\Users\stutzmann\Documents\saint-omer\st-omer\sources\catalogues\notices\biblio-saint-omer.xml"))}
Nota: for a reason of license, I am on version 21.1. Maybe a solved bug which I have not found in the forum.

Cheers

sorin_carbunaru
Posts: 384
Joined: Mon May 09, 2016 9:37 am

Re: Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by sorin_carbunaru » Tue Feb 02, 2021 5:27 pm

Hi Dominique,

Does it work if you use the doc() function and you provide a URL instead of a file path?

For example, something like this:

Code: Select all

${xpath_eval(doc('file:/C:/Users/me/Desktop/test.xml')/root/@id/string())}
Cheers,
Sorin

stutzmann
Posts: 15
Joined: Fri Mar 29, 2019 12:25 am

Re: Syntax for ${xpath_eval} and xpath function document() for external documents (URL, ${cfdu}, parent folder)

Post by stutzmann » Tue Feb 02, 2021 6:07 pm

Hi Sorin,

thanks, that is the answer!
The following adaptations based on your advice all work, with for all options (full path, relative path, url):

Code: Select all

${xpath_eval(doc('file:/C:/Users/UserName/Documents/project/sources/biblio.xml'))}

Code: Select all

${xpath_eval(doc('${cfdu}\biblio.xml'))}

Code: Select all

${xpath_eval(doc('https://raw.githubusercontent.com/ANYURL.xml'))}
Again, many thanks,
Dominique


Post Reply