[x3d-public] x3d.py roundtrip for Metadata nodes in v.3.3 and v.4.0

Andreas Plesch andreasplesch at gmail.com
Wed Nov 1 12:14:31 PDT 2023


I had better luck with

https://martin-honnen.github.io/xslt3fiddle/

for easy testing and did get to a first result with xslt modification:

https://github.com/andreasplesch/x3d-python-mod/blob/main/src/X3duomToX3dPythonPackageCF.xslt

This augmented xslt adds CONTAINERFIELD_DEFAULT() class methods, and
uses it to check against default containerField values, and otherwise
does more or less what the awk script did.

I had to essentially disable the tooltip functionality to get the
online xslt3 fiddle to work.

X3DUOM V.4.0  processed with the modified stylesheet generates

https://github.com/andreasplesch/x3d-python-mod/blob/main/x3dcf_V4.0.py

It is largely untested but seemed to run and added non-default
containerField attributes in an example.

-Andreas



On Wed, Nov 1, 2023 at 12:58 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
>
> I did take a look at the generator stylesheet but could not get very far.
> X3DUOM has the containerField default information separate from
> fields, so it could not be processed along with the fields. Perhaps a
> static CONTAINERFIELDDEFAULT() class method could work at class init,
> and then be used to check at XML output.
> I tried
>
> https://linangdata.com/xslt-tester/
>
> for no-setup fiddling with SaxonJS2. It takes the large X3DUOM xml and
> the large xslt but there is a dependance on the external tooltips xml
> document which I could not get rid of.
>
> It should be possible to use Python etree or similar to first ingest
> X3DUOM default containerField data, add a class method like above to
> each concrete Node in x3d.py, and then do the same as the awk script.
>
> -Andreas
>
> On Wed, Nov 1, 2023 at 10:23 AM Andreas Plesch <andreasplesch at gmail.com> wrote:
> >
> > A quick update:
> >
> > On Tue, Oct 31, 2023 at 3:49 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
> > >
> > > Notes:
> > >
> > > x3d.py is autogenerated from X3DUOM:
> > >
> > > https://www.web3d.org/x3d/stylesheets/python/python.html#autogeneration
> > > https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3duomToX3dPythonPackage.xslt
> > >
> > > X3DUOM has all necessary containerField default value information.
> > >
> > > But the first step may be to modify the stylesheet to generate
> > > containerField attributes for all nodes, for simplicity. It looks like
> > > the .XML() function would have to have an additional parameter 'field'
> > > X3D(indentLevel, syntax, field) for each node.
> > >
> > > Postprocessing the generated XML is not possible since information was
> > > irretrievably lost. But postprocessing the autogenerated x3d.py python
> > > code may be possible since xslt is not for everyone.
> >
> > As a proof of concept I hacked a short awk (since I know it) script to
> > process the latest x3d.py to include containerField support:
> >
> > https://github.com/andreasplesch/x3d-python-mod/blob/main/src/cfXML.awk
> >
> > It looks for the Concrete Nodes section, adds a field parameter to the
> > .XML() output function, adds the containerField attribute to the
> > output, and adds the field parameter to the .XML() calls for metadata,
> > SFNode and MFNode field processing.
> > The awk script is very brittle since it relies on comments in x3d.py
> > to find the appropriate lines to modify. The hardest part was to get
> > the quoting and escaping correct.
> > It generates containerField attributes for all SF/MFNode fields except
> > 'children'. Of course, most are unnecessary but filtering
> > systematically for defaults would probably require involving X3DUOM
> > and the generation stylesheet, similar to other XML related 'fields'
> > such as style or class.
> >
> > The result is https://raw.githubusercontent.com/andreasplesch/x3d-python-mod/main/x3dcf.py
> >
> > The modified python script appears to work as expected by adding the
> > appropriate containerField attributes in XML output for all the
> > examples I tried.
> > Realistically, this is as far as I can go with this but I think it may
> > show how containerField support in XML output could be provided with
> > x3d.py.
> >
> > -Andreas
>
>
>
> --
> Andreas Plesch
> Waltham, MA 02453



--
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list