Ticket #344 (closed question: fixed)

Opened 3 years ago

Last modified 3 years ago

Integrating the JOMDoc XSLT handling

Reported by: cmueller Owned by: dmisev
Priority: major Milestone: Release v0.1.3
Component: XSLT Version:
Keywords: Cc: nmueller
Blocked By: Blocking:
Due to close: YYYY/MM/DD Include in GanttChart: no
Dependencies: Due to assign: YYYY/MM/DD

Description (last modified by cmueller) (diff)

concerning ticket:343

The org.omdoc RendererFactory? does not allow to set an XSLT. Can you please explain which class/ method I should use to provide an input and XSLT Document as input and to receive a converted XOM document? Thank you!

I am particularly interested to switch the language parameters of the XSLT. Should I use org.omdoc.jomdoc.util.xml.XSLTUtil.transform(Document doc, Context params)? I don't understand how and where the parameters are considered in that method. Can you please explain? Cheers.

Another question refers to ref elements. How are these currently handled? When trying to convert the below document to XHTML, I get an error. Ideally, the ref would not be automatically resolved but rather be replaced by links. Would it be possible to adapt the XSLTs to take a parameter to either resolve refs or convert them into XHTML links?

Input document:

<?xml version="1.0"?>
<omdoc xmlns="http://omdoc.org/ns" 
xmlns:om="http://www.openmath.org/OpenMath" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:cc="http://creativecommons.org/ns" 
xmlns:m="http://www.w3.org/1998/Math/MathML" modules="CD" version="1.8" xml:id="d21d39ff-68bf-45fe-b7c3-957be6c0d841">
  <ref type="include" xml:id="b6824bc8-7c4b-4415-87b1-1a2e137596da" 
xref="910bac8a-88dc-48c5-98ea-41c5a6bdc8a2" />
  <ref type="include" xml:id="50e76767-38a6-421e-a895-1bd134423e38" 
xref="fc72c925-eb6c-40d7-9d0a-a6d4f28ae657" />
</omdoc>

Error message and output

Processing included Document 3f30537c-9ca2-41ba-88d9-0eb9a701a185 (xref 7ec1974c-ca7d-4653-ae40-3f489f1d81d7) ...
Recoverable error on line 123 
  FODC0002: java.net.MalformedURLException
Processing included Document 3cb0dffe-1d62-42b5-a6dc-37570a719395 (xref d58dfe47-4ada-44e9-aad9-2b6b8f61063f) ...
Recoverable error on line 123 
  FODC0002: java.net.MalformedURLException

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" id="3811a2e5-6174-46c8-b99e-780d4b016083">
   <head>
      <link rel="stylesheet" type="text/css" href="omdoc-default.css" />
      <title />
   </head>
   <body>
</body>
</html>

Change History

  Changed 3 years ago by cmueller

  • cc nmueller added
  • description modified (diff)

  Changed 3 years ago by cmueller

  • description modified (diff)

follow-up: ↓ 4   Changed 3 years ago by dmisev

For the xslt yes, after the rendering use org.omdoc.jomdoc.util.xml.XSLTUtil.transform(Document doc, Context params), set the xslt parameters through the params. Since you're directly working with the code I'd suggest you to also generate and use the javadoc, ant doc ;) But it's my fault I've forgotten to document params.

As for the refs I don't know, they aren't resolved in the rendering process (I have no idea about the xslts). Only OMR's are resolved in JOMDoc (but silently, you won't get any errors if it fails). I guess you should ask Christoph about this.

in reply to: ↑ 3   Changed 3 years ago by cmueller

Replying to dmisev:

For the xslt yes, after the rendering use org.omdoc.jomdoc.util.xml.XSLTUtil.transform(Document doc, Context params), set the xslt parameters through the params. Since you're directly working with the code I'd suggest you to also generate and use the javadoc, ant doc ;)

I am looking at the documentation in the code, that should be the same as what I get in the javadoc, shouldn't it? Anyway, when I wasted some time on testing out-dated methods for the ref expansion, you told me I should have asked you in the first place. So I learn, and I always prompt you first now ;-)

But it's my fault I've forgotten to document params.

What kind of Context values are recognized? Only the language parameter? Can you please provide an example of a Context object that would work? Or rather point me to the unit test you use, I can't find it. Cheers.

For example, with the below document, I am providing a Context object with value (language:en), but the parameters are not considered. I get the below output as if not providing a Context object at all.

Input document:

<?xml version="1.0" encoding="UTF-8"?>
<omdoc xml:id="CMP-variant" modules="CD" version="1.8" xmlns="http://omdoc.org/ns"
  xmlns:om="http://www.openmath.org/OpenMath" xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://creativecommons.org/ns" xmlns:m="http://www.w3.org/1998/Math/MathML">

 <theory xml:id="theory-cmp-var">
   <omtext xml:id="omtext-var-en" >
     <CMP xml:lang="de"> This is an English text.</CMP>
     <CMP xml:lang="en"> Die ist ein deutscher Text.</CMP>
   </omtext>
 </theory> 

 <theory xml:id="theory-cmp-var2">
   <omtext xml:id="omtext-var-en2" >
     <CMP ic="language:de"> This is an English text.</CMP>
     <CMP ic="language:en"> Die ist ein deutscher Text.</CMP>
   </omtext>
 </theory> 
</omdoc>

Output document:

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" id="ea9bd90f-b944-4e24-8da4-9f5562e45556">
   <head>
      <link rel="stylesheet" type="text/css" href="omdoc-default.css" />
      <title />
   </head>
   <body>
      <div xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" class="theory">
         <div class="omdoc-omtext" id="9c3a216c-6d5e-46bb-8ee4-61564fa302e8">
            <p> Die ist ein deutscher Text.</p>
         </div>
      </div>
      <div xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" class="theory">
         <div class="omdoc-omtext" id="3f9985be-b090-4d43-9499-a00c8f57ef61">
            <p> This is an English text.</p>
            <p> Die ist ein deutscher Text.</p>
         </div>
      </div>
   </body>
</html>

As for the refs I don't know, they aren't resolved in the rendering process (I have no idea about the xslts). Only OMR's are resolved in JOMDoc (but silently, you won't get any errors if it fails). I guess you should ask Christoph about this.

Okay, I will. See ticket:345

follow-up: ↓ 8   Changed 3 years ago by dmisev

TargetLanguage?=en, see #164

What kind of Context values are recognized? Only the language parameter? Can you please provide an example of a Context object that would work? Or rather point me to the unit test you use, I can't find it. Cheers.

I don't know, depends on what parameters are recognized by the xslts, the Context is simply a container for key/value pairs, I don't do any checks in the code whether it's language or TargetLanguage? or lang. In other words Context is equivalent to List<Pair<String, String>> here.

in reply to: ↑ description ; follow-up: ↓ 7   Changed 3 years ago by clange

Part of the comment you requested from me in #345 rather fits here, namely the explanation of ref/@xref:

<ref type="include" xml:id="b6824bc8-7c4b-4415-87b1-1a2e137596da" xref="910bac8a-88dc-48c5-98ea-41c5a6bdc8a2" />

This is a reference to a relative URL. In the file system, the target is expected to be a file named 910bac8a-88dc-48c5-98ea-41c5a6bdc8a2. Not sure what you want with these IDs, but if you mean the xml:id of a node in the same document, the attribute would have to be xref="#910...". Any Java application running XSLT can, however, define its own URIResolver (RTFM javax.xml.transform.URIResolver for details). In theory, you could define a resolver that recognizes those GUID-like URIs and treats them specially. But you need to be careful not to violate the specs of URIs: As long as you also support links to local files, what if somebody dared to name a file 910...?

in reply to: ↑ 6   Changed 3 years ago by cmueller

Replying to clange:

Part of the comment you requested from me in #345 rather fits here, namely the explanation of ref/@xref:

<ref type="include" xml:id="b6824bc8-7c4b-4415-87b1-1a2e137596da" xref="910bac8a-88dc-48c5-98ea-41c5a6bdc8a2" />

This is a reference to a relative URL. In the file system, the target is expected to be a file named 910bac8a-88dc-48c5-98ea-41c5a6bdc8a2. Not sure what you want with these IDs, but if you mean the xml:id of a node in the same document, the attribute would have to be xref="#910...". Any Java application running XSLT can, however, define its own URIResolver (RTFM javax.xml.transform.URIResolver for details). In theory, you could define a resolver that recognizes those GUID-like URIs and treats them specially. But you need to be careful not to violate the specs of URIs: As long as you also support links to local files, what if somebody dared to name a file 910...?

I am converting the ids from the imported documents into unique identifiers in my in-memory repository. Thus the xrefs are not pointing to files in the file system but items in the database. see ticket:346

in reply to: ↑ 5   Changed 3 years ago by cmueller

Replying to dmisev:

TargetLanguage?=en, see #164

What kind of Context values are recognized? Only the language parameter? Can you please provide an example of a Context object that would work? Or rather point me to the unit test you use, I can't find it. Cheers.

I don't know, depends on what parameters are recognized by the xslts, the Context is simply a container for key/value pairs, I don't do any checks in the code whether it's language or TargetLanguage? or lang. In other words Context is equivalent to List<Pair<String, String>> here.

Have you done any testing, whether the language parameter is passed on the the XSLT and converts the document respectively? I have the feeling that the parameters are not yet passed on to the XSLT. Would you please create a unit test that adapts the above document to English, removing all German text via the XSLT? Cheers.

follow-up: ↓ 10   Changed 3 years ago by dmisev

in reply to: ↑ 9   Changed 3 years ago by cmueller

Replying to dmisev:

Yes I have done, see  https://jomdoc.omdoc.org/ticket/164#comment:5

Ah yes I see, that was the ticket I couldn't find ;-). ContextParameters? like "language:en" are not working, JOMDoc currently only supports "TargetLanguage:en". Could you please extend this to also accept "language:en" and "lang:en"? Thank you!

follow-up: ↓ 12   Changed 3 years ago by dmisev

  • status changed from new to closed
  • resolution set to fixed

in reply to: ↑ 11   Changed 3 years ago by cmueller

  • status changed from closed to reopened
  • resolution fixed deleted

Replying to dmisev: I'd like to test this, but unfortunately I can't compile your lattest implementation.

BUILD FAILED
/home/cmueller/vc/svn/omdoc.org/jomdoc/src/jomdoc/trunk/build.xml:97: Compile failed; see the compiler error output for details.

follow-up: ↓ 14   Changed 3 years ago by dmisev

  • status changed from reopened to closed
  • resolution set to fixed

Ups sorry about that

in reply to: ↑ 13   Changed 3 years ago by cmueller

  • status changed from closed to reopened
  • resolution fixed deleted

Replying to dmisev:

Ups sorry about that

No problems, works fine now ;-)

I just tried the following command from ticket:164:

jomdoc transform ../testdata/xsltutil/targetLanguage.omdoc -X --xsl-param TargetLanguage=de -o targetLanguage-de.xhtml

and received the below error:

...
<xsl:include href="omdoc2pmml-nomobj.xsl" />
<xsl:include href="pmml/copy-mobj.xsl" />
</xsl:stylesheet>

Recoverable error on line 36
  FODC0002: java.net.MalformedURLException

Could you please have a look?

  Changed 3 years ago by dmisev

  • status changed from reopened to closed
  • resolution set to fixed

  Changed 3 years ago by cmueller

  • status changed from closed to reopened
  • resolution fixed deleted

Great, thanks for fixing this. I can run the command line example now.

However, I still haven't figured out how you do it, sorry, but could you please help me out? Could you please point me to a unit test in src/tests, so I can follow the internal processing in JOMDoc? I thought I had the integration of the parametrizable XSLT working, but apparently I was wrong (because I messed up my input document). It does not consider my Context objects to adapt the below input document. Into which Context Object do you parse the commandline? Into Pair(TargetLanguage?, de)?

My Context object and call of JOMDoc

  public Document configureFormat(Document input) {
    Context xslt = new Context();
    xslt.add("language", "de");
    return XSLTUtil.transform(input, xslt);
  }

Input Document

<?xml version="1.0" encoding="UTF-8"?>
<omdoc xml:id="CMP-variant" modules="CD" version="1.8" xmlns="http://omdoc.org/ns"
  xmlns:om="http://www.openmath.org/OpenMath" xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://creativecommons.org/ns" xmlns:m="http://www.w3.org/1998/Math/MathML">

 <theory xml:id="theory-cmp-var">
   <omtext xml:id="omtext-var-en" >
     <CMP> This is an English text.</CMP>
     <CMP xml:lang="de"> Die ist ein deutscher Text.</CMP>
   </omtext>
 </theory> 

 <theory xml:id="theory-cmp-var2">
   <omtext xml:id="omtext-var-en2" >
     <CMP> This is an English text.</CMP>
     <CMP ic="language:de"> Die ist ein deutscher Text.</CMP>
   </omtext>
 </theory> 
</omdoc>

Output

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" id="uuid-c1f6e560-fa86-43d4-8699-0541d4a3db53">
   <head>
      <link rel="stylesheet" type="text/css" href="omdoc-default.css" />
      <title />
   </head>
   <body>

      <div xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" class="theory">
         <div class="omdoc-omtext" id="uuid-7f3c1c60-2d23-4177-aa0c-7d9e64d86130">
            <p> This is an English text.</p>
         </div>
      </div>
      <div xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" class="theory">
         <div class="omdoc-omtext" id="uuid-51d59c3a-ae94-4039-80db-5c168bec9ebd">
            <p> This is an English text.</p>

            <p> Die ist ein deutscher Text.</p>
         </div>
      </div>


   </body>
</html>

Thanks a lot for your patience and help!

follow-up: ↓ 18   Changed 3 years ago by dmisev

I simply say context.addPair(value); where value is "TargetLanguage?=de", the string from the command line. Maybe your input file is wrong, try with the test I have created, testdata/xsltutil/targetLanguage.omdoc.

in reply to: ↑ 17   Changed 3 years ago by cmueller

Replying to dmisev:

I simply say context.addPair(value); where value is "TargetLanguage?=de", the string from the command line. Maybe your input file is wrong, try with the test I have created, testdata/xsltutil/targetLanguage.omdoc.

I have been using your example, but still can't get it to work.

I pass the following two parameters to JOMDoc:

Input:

<?xml version="1.0"?>
<omdoc xmlns="http://omdoc.org/ns" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns" version="1.6" modules="CD" xml:id="pomdoc-2db48ca8-26d7-4442-ade9-9b39d0fe263e">
    <theory xml:id="pomdoc-5030022e-0c96-4737-ac76-5b87ca1355b0">

        <assertion type="lemma" theory="pomdoc-5030022e-0c96-4737-ac76-5b87ca1355b0" xml:id="pomdoc-5efdb268-dbbc-49a1-95bc-bc3e93ced55a">
            <CMP>
                English
            </CMP>
            <CMP xml:lang="de">
                Deutsch
            </CMP>
        </assertion>
    </theory>
</omdoc>

and the Context

    Context xslt = new Context();
    xslt.addPair("TargetLanguage=de");

Then I call JOMDoc. Is that the right method, I am using? Anyway, using it I only get the default in English. Maybe the method I use, uses a different XSLT?

XSLTUtil.transform(input, xslt);

Do you have an idea what might be going wrong here? Maybe it would help, if you could write a unit test in JOMDoc/src/test. Then I can debug the working workflow in JOMDoc and compare it to mine. Thank you.

  Changed 3 years ago by cmueller

Actually, I just looked into the generated targetLanguage-de.xhtml again, it is in English also I provide TargetLanguage?=de. So I believe there is a bug in JOMDoc in calling the XSLT with the right parameters. Could you please have a look? Cheers.

  Changed 3 years ago by dmisev

  • status changed from reopened to closed
  • resolution set to fixed

Yes you're right, it wasn't working with the -X option that one is a separate method, I only had implemented this for -x. Sorry for the problems :( It should work now.

Note: See TracTickets for help on using tickets.