這個問題在這里已經有了答案: 在 xslt:value-of select 中使用 XPATH 來填充 attritube (1 個回答) 3 天前關閉。
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>
下面的代碼是xslt的代碼,使用XSL語言和DOT語言規則。
<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 有兩種型別的元素,即:節點和邊。在第一個節點上,我想在 xml 中的角色元素上獲取角色值,并且我想將該值分配給我的 xsl 檔案中的節點元素。其次,我想在 xml 檔案的 pns 子選單中的 url 元素上獲取 url 值,并且我想將該值分配給我的 xsl 檔案中的節點元素。其次,我想在 xml 檔案的 pns 子選單中的 url 元素上獲取 url 值,并且我想將該值分配給我的 xsl 檔案中的節點元素。第三,我想在 xml 檔案的 pppk 子選單中的 url 元素上獲取 url 值,并且我想將該值分配給我的 xsl 檔案中的節點元素。四、我想獲取xml檔案中ppt子選單中url元素上的url值,
我有一個問題,當我使用 SAXONICA 轉換我的 xml 檔案時,我的 XSL 檔案中出現錯誤,如下所示
與元素型別“節點”關聯的元素不得包含“<”字符。org.xml.sax.SAXParseException; systemId: 檔案:/C:/Users/rafif/Desktop/saxons/role-policy.xsl; 行號:5;列數:27;與元素型別“節點”關聯的屬性“id”的值不得包含“<”字符。org.xml.sax.SAXParseException; systemId: 檔案:/C:/Users/rafif/Desktop/saxons/role-policy.xsl; 行號:5;列數:27;與元素型別“節點”關聯的屬性“id”的值不得包含“<”字符。org.xml.sax.SAXParseException; systemId: 檔案:/C:/Users/rafif/Desktop/saxons/role-policy.xsl; 行號:5;列數:27;與元素型別“節點”關聯的屬性“id”的值不得包含“<”字符。
can you help me to fix my XSL code
uj5u.com熱心網友回復:
您不能將一個元素放置在另一個元素的開始標簽內。代替:
<node id="<xsl:value:of select='role'>" label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16"/>
使用:
<node label="role:siasn-instansi:profilasn:viewprofil" style="filled" fontsize="16">
<xsl:attribute name="id">
<xsl:value-of select='role'/>
</xsl:attribute>
</node>
或(參見: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"/>
您還需要<xsl:for-each>正確關閉元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/363084.html
上一篇:XSL風格:在XSLT中使用<xsl:for-eachselect>或<xsl:templatematch>或其他解決方案?
下一篇:Python/BeautifulSoup-從clinicaltrials.gov中提取XML資料,只能提取沒有缺失資料的研究
