[x3d-public] ChatGPT —run this prompt

John Carlson yottzumm at gmail.com
Thu Mar 23 04:26:04 PDT 2023


<xsl:stylesheet version="2.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:xs="
http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
  <xsl:output method="text"/>

  <!-- Define mapping of ConcreteNodes to JSON schema -->
  <xsl:template match="X3D/Scene">
    <xsl:text>{&#xa;</xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template match="node()">
    <xsl:param name="indent" select="'  '"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$indent"/>
    <xsl:text>"</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>" : {</xsl:text>
    <xsl:apply-templates select="@* | *"/>
    <xsl:value-of select="$indent"/>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:param name="indent" select="'  '"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$indent"/>
    <xsl:text>"@</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>" : "</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>"</xsl:text>
  </xsl:template>

  <xsl:template match="node()[not(*)]">
    <xsl:param name="indent" select="'  '"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$indent"/>
    <xsl:text>"-</xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>" : { "type" : "</xsl:text>


On Thu, Mar 23, 2023 at 6:23 AM John Carlson <yottzumm at gmail.com> wrote:

> Here's an example of XSLT code that creates a mapping from the input X3D
> unified object model ConcreteNodes to JSON subschema objects, using XSLT to
> generate JSON. The code uses recursion and lists to handle a large number
> of ConcreteNodes in shorter code, and puts "@" in front of SF-prefixed
> field type property names and "-" in front of MF-prefixed field type
> property names
>
> <xsl:stylesheet version="2.0" xmlns:xsl="
> http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"
> indent="yes"/>
>
>   <xsl:variable name="SF_prefix" select="'@'"/>
>   <xsl:variable name="MF_prefix" select="'-'"/>
>
>   <xsl:template match="/">
>     <xsl:text>{</xsl:text>
>     <xsl:apply-templates select="x3d/ConcreteNode"/>
>     <xsl:text>&#xa;}</xsl:text>
>   </xsl:template>
>
>   <xsl:template match="ConcreteNode">
>     <xsl:text>&#xa;"</xsl:text>
>     <xsl:value-of select="@name"/>
>     <xsl:text>": {</xsl:text>
>     <xsl:apply-templates select="field"/>
>     <xsl:text>&#xa;}</xsl:text>
>     <xsl:if test="position() != last()">
>       <xsl:text>,</xsl:text>
>     </xsl:if>
>   </xsl:template>
>
>   <xsl:template match="field">
>     <xsl:text>&#xa;"</xsl:text>
>     <xsl:value-of select="@name"/>
>     <xsl:text>": </xsl:text>
>     <xsl:choose>
>       <xsl:when test="@type = 'SFBool' or @type = 'SFDouble' or @type =
> 'SFInt
>
>
> On Thu, Mar 23, 2023 at 6:10 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> I’ll be posting my chatGPT results here, probably in several messages.
>>
>> <xsl:stylesheet version="2.0" xmlns:xsl="
>> http://www.w3.org/1999/XSL/Transform" xmlns:x3d="
>> http://www.web3d.org/specifications/x3d-namespace" xmlns:json="
>> http://www.json.org" exclude-result-prefixes="x3d"> <xsl:output method=
>> "text" omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:text>{
>> </xsl:text> <xsl:apply-templates select="//x3d:*" /> <xsl:text>&#xA;}</
>> xsl:text> </xsl:template> <xsl:template match="x3d:*[@containerField =
>> 'children']"> <xsl:text>"</xsl:text> <xsl:value-of select="local-name()"
>> /> <xsl:text>":[</xsl:text> <xsl:apply-templates select="*" /> <xsl:text>
>> ]</xsl:text> <xsl:if test="following-sibling::*[@containerField =
>> 'children']"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> <
>> xsl:template match="x3d:*"> <xsl:text>"</xsl:text> <xsl:value-of select=
>> "local-name()" /> <xsl:text>":{</xsl:text> <xsl:apply-templates select=
>> "@*" /> <xsl:text>}</xsl:text> <xsl:if test="following-sibling::*[@containerField
>> = 'children']"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> <
>> xsl:template match="@*[starts-with(local-name(), 'SF')]"> <xsl:text>"@</
>> xsl:text> <xsl:value-of select="local-name()" /> <xsl:text>":</xsl:text>
>> <xsl:choose> <xsl:when test="starts-with(local-name(), 'SFInt')"> <
>> xsl:text>"number"</xsl:text> </xsl:when> <xsl:when test="starts-with(local-name(),
>> 'SFFloat')"> <xsl:text>"number"</xsl:text> </xsl:when> <xsl:when test="starts-with(local-name(),
>> 'SFBool')"> <<span class="hljs-name" style="border: 0px solid rgb(217,
>> 217, 227); box-sizing: border-box; --tw-border-spacing-x: 0;
>> --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0;
>> --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1;
>> --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ;
>> --tw-scroll-snap-strictness: proximity; --tw-ordinal: ; --tw-slashed-zero:
>> ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ;
>> --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color:
>> #fff; --tw-ring-color: rgba(59,130,246,0.5); --tw-ring-offset-shadow: 0 0
>> transparent; --tw-ring-shadow: 0 0 t
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230323/5b010d8e/attachment-0001.html>


More information about the x3d-public mailing list