-1
I have an xml code as shown below, The xml contains several elements, namely: id, parent menu, label, role id, role and items. in items there is 1 element, namely submenu, and in submenu there are 2 elements, namely url and label:

<?xml version="1.0" encoding="UTF-8"?>
<Import>
    <Row>
        <id>1</id> //this the id
        <parentmenu>siasn-instansi</parentmenu> //this is the parent menu
        <label>Layanan Profile ASN</label> //this is the label
        <role_id>1</role_id> //this is the role id
        <role>role:siasn-instansi:profilasn:viewprofil</role> //this is the role
        <items>
            <subMenu name = "pns"> //this is the Sub menu
                 <url>/tampilanData/pns</url> //this is the url
                 <label>Profile Pegawai</label> //this is the label
            </subMenu>
            <subMenu name = "pppk"> //this is the Sub menu
                 <url>/tampilanData/pppk</url> //this is the parent menu
                 <label>Profile Pegawai PPPK</label> //this is the label
            </subMenu>
            <subMenu name = "ppt"> //this is the Sub menu
                 <url>/tampilanData/JPTNonASN</url> //this is the url
                 <label>Profile Pegawai PPT Non-ASN</label> //this is the label
            </subMenu>
        </items>
    </Row>
</Import>

and the code below is the code for the xslt, using XSL language with DOT language rules.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:dotml="http://www.martin-loetzsch.de/DOTML" version="1.0"> //xsl to transform to dot file
    <xsl:template match="/">
        <xsl:for-each select = "Import/Row">
            <graph file-name="graphs/node">  
                <node id="<xsl:value:of select='role'>" label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16"/> //in this case i wanna take the value in my xml code to take place in id on my element node in xsl
                <node id="<xsl:value:of select='items/subMenu[@name="pns"]/url'>" label="/tampilanData/pns" style="filled" fontsize="16"/>
                <node id="<xsl:value:of select='items/subMenu[@name="pppk"]/url'>" label="/tampilanData/pppk" style="filled" fontsize="16"/>
                <node id="<xsl:value:of select='items/subMenu[@name="ppt"]/url'>" label="/tampilanData/JPTNonASN" style="filled" fontsize="16"/>
                <edge from="<xsl:value:of select='role'>" to="<xsl:value:of select='items/subMenu[@name="pns"]/url'>" fontname="Arial" fontsize="9" label="Permit"/>
                <edge from="<xsl:value:of select='role'>" to="<xsl:value:of select='items/subMenu[@name="pppk"]/url'>" fontname="Arial" fontsize="9" label="Permit"/>
                <edge from="<xsl:value:of select='role'>" to="<xsl:value:of select='items/subMenu[@name="ppt"]/url'>" fontname="Arial" fontsize="9" label="Permit"/>
            </graph>
        <xsl:for-each>    
    </xsl:template>    
</xsl:stylesheet>

xsl there are 2 types of elements, namely: nodes and edges. on the first node, I want to take the role value on the role element in xml, and I want to assign that value to the node element in my xsl document. second, I want to fetch the url value on the url element in the pns submenu in the xml document, and I want to assign that value to the node element in my xsl document. second, I want to fetch the url value on the url element in the pns submenu in the xml document, and I want to assign that value to the node element in my xsl document. Third, I want to fetch the url value on the url element in the pppk submenu in the xml document, and I want to assign that value to the node element in my xsl document. Fourth, I want to fetch the url value on the url element in the ppt submenu in the xml document, and I want to assign that value to the node element in my xsl document element.

I have a problem, when I convert my xml document using SAXONICA, an error occurs in my XSL document as shown below

C:\Users\rafif\Desktop\saxons>java -jar saxon-he-10.6.jar role-policy.xml role-policy.xsl -o:role-policy.dot Error on line 5 column 27 of role-policy.xsl: SXXP0003 Error reported by XML parser: The value of attribute "id" associated with an element type "node" must not contain the '<' character.: The value of attribute "id" associated with an element type "node" must not contain the '<' character. org.xml.sax.SAXParseException; systemId: file:/C:/Users/rafif/Desktop/saxons/role-policy.xsl; lineNumber: 5; columnNumber: 27; The value of attribute "id" associated with an element type "node" must not contain the '<' character.

can you help me to fix my XSL code
  • Comments in XML are written like this ``. When you post code for others, please do not fill it with "comments" like this `//this is a comment` - it only wastes their time. Note also that the instruction is`xsl:value-of`, not `xsl:value:of`. – michael.hor257k Nov 19 '21 at 06:52

1 Answers1

0

You cannot place an element inside the start-tag of another element. Instead of:

<node id="<xsl:value:of select='role'>" label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16"/>

use either:

<node label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16">
    <xsl:attribute name="id">
        <xsl:value-of select='role'/>
    </xsl:attribute>
</node> 

or (see: https://www.w3.org/TR/1999/REC-xslt-19991116/#attribute-value-templates):

<node id="{role}" label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16"/>

You also need to close the <xsl:for-each> element properly.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51