[x3d-public] [Remaining Work] X3dToPython.xslt, BooleanSequencer keyValue

John Carlson yottzumm at gmail.com
Tue Jul 5 14:47:10 PDT 2022


The patch for X3dToJson.xslt appears to be much more complex than I
thought! Ouch!

On Tue, Jul 5, 2022 at 11:41 AM John Carlson <yottzumm at gmail.com> wrote:

> I don't know what normalize-space does right now, but I trust you!  Your
> results look good, Thanks!
>
> I may follow-with testing later.  I'd like to include a JSON patch based
> on your patch.
>
> John
>
> On Tue, Jul 5, 2022 at 11:28 AM Brutzman, Donald (Don) (CIV) <
> brutzman at nps.edu> wrote:
>
>> [Summary: X3D to Python MFBool conversion problem fixed.]
>>
>>
>>
>>    1. Thanks for diagnosis and focus on correct code block.  The actual
>>    conversion problem was failure to normalize whitespace (including original
>>    commas) before changing blank characters to comma separators in final
>>    output.  Thus multiple blank and comma characters (which together are
>>    allowed whitespace in the XML output) were previously getting converted to
>>    multiple commas, ouch.
>>
>>
>>
>> Revised XSLT:
>>
>>    - <xsl:variable name="commaSeparatedMFBool"
>>    select="translate(normalize-space(translate(translate(translate(string($x3dValue),'f','F'),'t','T'),',','
>>    ')),' ',',')"/>
>>
>>
>>
>> I modified a test scene and checked the converted output:
>>
>>    -
>>    https://www.web3d.org/x3d/content/examples/Basic/development/BooleanSequencerExample.x3d
>>    -
>>    https://www.web3d.org/x3d/content/examples/Basic/development/BooleanSequencerExample.py
>>
>>
>> Revised model excerpts and correct output with diagnostic turned on:
>>
>>
>>
>>    - <BooleanSequencer DEF='LeftViewBinder' key='0 0.1 0.25'
>>    keyValue='false true false'/>
>>    - <BooleanSequencer DEF='BackViewBinder' key='0 0.375 0.475'
>>    keyValue='false, true, false'/>
>>    - <BooleanSequencer DEF='RightViewBinder' key='0 0.5 0.6'
>>    keyValue='false , true , false'/>
>>
>>
>>
>> create python:
>>
>> C:\x3d-code\www.web3d.org\x3d\content\examples\Basic/development//BooleanSequencerExample.x3d
>> processing with X3dToPython stylesheet...
>>
>> *** MFBool handling, $x3dValue='false true false,
>> $commaSeparatedMFBool='False,True,False
>>
>> *** MFBool handling, $x3dValue='false, true, false,
>> $commaSeparatedMFBool='False,True,False
>>
>> *** MFBool handling, $x3dValue='false , true , false,
>> $commaSeparatedMFBool='False,True,False
>>
>>
>>
>>    -
>>    BooleanSequencer(DEF='LeftViewBinder',key=[0,0.1,0.25],keyValue=[False,True,False]),
>>    -
>>    BooleanSequencer(DEF='BackViewBinder',key=[0,0.375,0.475],keyValue=[False,True,False]),
>>    -
>>    BooleanSequencer(DEF='RightViewBinder',key=[0,0.5,0.6],keyValue=[False,True,False]),
>>
>>
>>
>> Original test scene goes back to original state, since X3D
>> Canonicalization (C14N) changes those pesky commas back into single blank
>> characters.
>>
>>
>>
>>    - ISO/IEC 19776-3, Extensible 3D (X3D) encodings, Part 3: Compressed
>>    binary encoding
>>    - Annex 4 Concepts, Clause 4.2.3 X3D canonical form
>>    -
>>    https://www.web3d.org/documents/specifications/19776-3/V3.3/Part03/concepts.html#X3DCanonicalForm
>>
>>
>>
>>    - X3D Canonicalizer
>>    -
>>    https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/tools/canonical/doc/x3dTools.htm
>>
>>
>>
>> X3dToPython.xslt stylesheet committed, changes should be good for you now.
>>
>>
>>
>>    1. Regarding rephrased tooltip for MFBool: please note
>>
>>
>>    1. All such hints are similarly / identically phrased for
>>    maintainability,
>>    2. All tooltip hints are for XML encoding, too easily confused
>>    otherwise.
>>
>>
>>
>>    - X3D4 Tooltips, FieldTypesTable
>>    - https://www.web3d.org/x3d/tooltips/X3dTooltips.html#FieldTypesTable
>>    - For MFBool:
>>
>> *Hint:* comma characters are allowed as whitespace between individual
>> SFBool values in the list.
>> *Hint:* comma characters are not included in canonical form.
>>
>>
>>
>> So I think we are good.  Again thanks for a helpful catch.
>>
>>
>>
>> all the best, Don
>>
>> --
>>
>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>> brutzman at nps.edu
>>
>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>> +1.831.656.2149
>>
>> X3D graphics, virtual worlds, Navy robotics https://
>> faculty.nps.edu/brutzman
>>
>>
>>
>> *From:* John Carlson <yottzumm at gmail.com>
>> *Sent:* Monday, July 4, 2022 7:25 PM
>> *To:* Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>; X3D Graphics
>> public mailing list <x3d-public at web3d.org>; holger.seelig at gmail.com
>> *Subject:* Re: [Remaining Work] X3dToPython.xslt, BooleanSequencer
>> keyValue
>>
>>
>>
>> Code in question in X3dToPython.xslt, I think, for MFBool's.
>>
>>
>>
>>             <xsl:when test="($x3dType = 'MFBool')">
>>                 <!-- Python boolean values are True and False,
>> comma-separated list -->
>>                 <xsl:value-of
>> select="translate(translate(translate(string($x3dValue),'f','F'),'t','T'),'
>> ',',')"/>
>>             </xsl:when>
>>
>>
>>
>> Spaces are translated to ',', i think, to "true, false" in XML gets
>> translated to "True,,False" in Python.
>>
>>
>>
>> I don't know how to fix this yet (I'm an XSLT plebe), except fix the XML
>> so Python will work okay.  Maybe we should put a feature request into Saxon
>> or ask for help?
>>
>>
>>
>> At this point, my suggestion would be to fall back to some kind of
>> regular expression replacement?
>>
>>
>>
>> Or what I would do in sed, like:
>>
>>
>>
>> s/,+/,/g
>>
>>
>>
>> and
>>
>>
>>
>> s/ +/ /g
>>
>>
>>
>> between SFBools
>>
>>
>>
>> One may wish to put \s or \S , from more advanced regular expressions,
>> and only allow one comma between SFBools in the MFBool.
>>
>>
>>
>> I don't know if XSLT supports any of this.  Check out this table for XSLT
>> 2.0?  Is this accurate?
>>
>>
>>
>> 16.4 Using Regular Expressions | Learning XSLT (flylib.com)
>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fflylib.com%2Fbooks%2Fen%2F2.424.1.122%2F1%2F&data=05%7C01%7Cbrutzman%40nps.edu%7Cfebd8a7a066b4c06d29108da5e2d9806%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637925847160880998%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=AfjPGqSrV4%2BwpPzxROzihR3yWwKSRezo89pEJWCXU3g%3D&reserved=0>
>>
>>
>>
>> Did a little googling, found this:
>>
>>
>>
>> regex - XSLT + regular expression replace - Stack Overflow
>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F35840063%2Fxslt-regular-expression-replace&data=05%7C01%7Cbrutzman%40nps.edu%7Cfebd8a7a066b4c06d29108da5e2d9806%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637925847160880998%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=YogJt1t6CIIgoer9GrMVA7rfWfN7RGU7wieOdYT714Y%3D&reserved=0>
>>  (analyze-string)
>>
>>
>>
>> Perhaps a few of us could attend an advanced XSLT course?
>>
>>
>>
>> Maybe we could have a learning session?  I only see one analyze-string in
>> our XSLT code base.
>>
>>
>>
>> Could be a big win, would be my guess.
>>
>>
>>
>> Or we could use SNOBOL or its derivative, Icon. Icon (programming
>> language) - Wikipedia
>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIcon_%2528programming_language%2529&data=05%7C01%7Cbrutzman%40nps.edu%7Cfebd8a7a066b4c06d29108da5e2d9806%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637925847160880998%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=QzM1Glrkto0CBwqHC6wZ6zx6ecYDM7vzLFvavlL7u%2BA%3D&reserved=0> (see
>> "Dialects" and "Influenced" for additional features, some 3D).
>>
>>
>> I studied Icon in school, and it was a good language, I didn't run into
>> any snafu's with our problem set solutions.
>>
>>
>>
>> I would recommend Icon over XML, XSLT, Python and JavaScript, if anyone
>> cares, at least for text processing.  I didn't do 3D with Icon.
>>
>>
>>
>> John
>>
>>
>>
>> On Mon, Jul 4, 2022 at 8:18 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Trying to help...For MFBool in X3d tooltips, perhaps rephrase whitespace
>> as below, for both XML, JSON and Python (and perhaps others).
>>
>>
>>
>> *Hint:* a single comma character is allowed as whitespace between
>> individual SFBool values in the list.
>>
>>
>>
>> Sorry, I apologize for bringing up MFStrings.  I was in the wrong.
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Jul 4, 2022 at 7:53 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> If commas are not allowed in XML for MFBool, then Holger needs to change
>> her particle system code.
>>
>>
>>
>>
>>
>> On Mon, Jul 4, 2022 at 7:49 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Note: Please clarify MFBool. I will look again at recent emails.
>>
>>
>>
>> My understanding is that SFBool values can be separated by /, / comma
>> followed by space in an MFBool in XML (comma as whitespace). What I'm not
>> understanding is the Python output from X3dToPython.xslt, which puts out
>> commas next to each other (comma not as whitespace).  See below.
>>
>>
>>
>> On Mon, Jul 4, 2022 at 4:56 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Note extra commas in MFBool outputs from X3dToPython.xslt and
>> X3dToJson.xslt.
>>
>>
>>
>> On Mon, Jul 4, 2022 at 4:23 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Note, the following examples are unvalidated. Beware!
>>
>>
>>
>> For example, from:
>> https://raw.githubusercontent.com/create3000/Library/main/Tests/Components/ParticleSystems/BoundedPhysicsModel.x3d
>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcreate3000%2FLibrary%2Fmain%2FTests%2FComponents%2FParticleSystems%2FBoundedPhysicsModel.x3d&data=05%7C01%7Cbrutzman%40nps.edu%7Cfebd8a7a066b4c06d29108da5e2d9806%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637925847160880998%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=YNS4TaXeAD7d0Cznh6VzX5gD81gEsGo6g7rGkaFV90g%3D&reserved=0>
>>
>>     <BooleanSequencer DEF='_4'
>>         key='0, 0.3, 1'
>>         keyValue='true, false'/>
>>
>>
>>
>> And python:
>>
>>
>>
>> BooleanSequencer(DEF='_4',key=[0,0.3,1],keyValue=[True,,False]),
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220705/e9d36fc7/attachment-0001.html>


More information about the x3d-public mailing list