1

This is my XML, which I want to convert into DOT:

<Import>
  <Row>
    <id>1</id>
    <parentmenu>siasn-instansi</parentmenu>
    <label>Layanan Profile ASN</label>
    <role_id>1</role_id>
    <role>role:siasn-instansi:profilasn:viewprofil</role>
    <items>[{"url": "/tampilanData/pns", "label": "Profile Pegawai", "subMenu": "pns"}, {"url": "/tampilanData/pppk", "label": "Profile Pegawai PPPK", "subMenu": "pppk"}, {"url": "/tampilanData/JPTNonASN", "label": "Profile Pegawai PPT Non-ASN", "subMenu": "ppt"}]</items>
  </Row>
</Import>

Below is a picture of my XSL code with the DOT file rules.

XSL code:

The problem is, I want to get the values from <items>, like below:

  • /displayData/pns
  • /displayData/pppk
  • /displayData/JPTNoASN

and I want to take the value points above into my XSL as outlined in red in the image.

How would the XSL look like that can take the values from my XML? The <items> value is quite difficult, unlike the <role> values, which I have managed to take.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • 2
    Please post your code **as code** within your question, not as picture in external link. Also include the exact result you expect to get (as code) and state which version of XSLT you can use. – michael.hor257k Nov 17 '21 at 09:26
  • Note: I've cleaned up your code a bit. I'm assuming that `` *actually* contains JSON, and that the missing closing quotes in that JSON were copy/paste accidents when you created the XML sample, so I fixed them. Also, `"` and `"` are exactly the same in this XML, so I've used `"` to make it more readable. Please go over you the XML sample and confirm. And, of course put in your XSLT code in text form and state your XSLT version, as Michael has requested. – Tomalak Nov 17 '21 at 10:59
  • This question might help: https://stackoverflow.com/questions/13007280/how-to-convert-json-to-xml-using-xslt – Wilko van der Veen Nov 17 '21 at 11:01

1 Answers1

0

In XSLT 3.0 you can do, for example:

<xsl:template match="items">
  <xsl:variable name="content" select="parse-json(.)/*" as="map(*)*"/>
  <xsl:for-each select="$content">
    url="{?url}"
    label="{?label}"
    menu="{?subMenu}"
  </xsl:for-each>
</xsl:template>

The parse-json() function returns an array of maps; the "/*" operator turns this into a sequence of maps; the construct ?url accesses a specific entry in a map.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164