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.

3
  • 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. Commented Nov 17, 2021 at 9:26
  • Note: I've cleaned up your code a bit. I'm assuming that <items> 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, &quot; 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. Commented Nov 17, 2021 at 10:59
  • This question might help: stackoverflow.com/questions/13007280/… Commented Nov 17, 2021 at 11:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.