[英]Create XSLT from an XML to get desired XML
我這里的情況:考慮以下代碼作為示例:
<?xml version="1.0" encoding="utf-8"?>
<school id="1" alias="abc" name="St.Josephs" val="">
<teacher id="1">Rose</teacher>
<subject>maths</subject>
</school>
<school id="2" alias="bcd" name="" val="">
<teacher id="2">john</teacher>
<subject>science</subject>
</school>
<school id="3" alias="abc" name="" val="">
<student rollno="12">sarah</student>
<age>13</age>
</school>
<school id="4" alias="bcd" name="St.Mary's" val="">
<student rollno="14">Rosh</student>
<age>14</age>
</school>
現在在這里,我需要設計一個XSLT,它將從別名為abc,bcd的元素同時創建具有包含數據的元素,其輸出將如下所示:
<Institutes>
<group>
<content>
<![CDATA[
<html>
<head>
<title>'Rose' is a 'Maths' teacher</title>
</head>
<body>
Rose is a maths teacher for sarah in St.josephs school
</body>
</html>
]]>
</content>
</group>
</Institutes>
<Institutes>
<group>
<content>
<![CDATA[
<html>
<head>
<title>'john' is a 'science' teacher</title>
</head>
<body>
john is a science teacher for Rosh in St.Mary's school
</body>
</html>
]]>
</content>
</group>
</Institutes>
Is there any way to achieve this..??
您需要使用樣式表頂部的xsl:output元素,以CDATA的形式列出所需的元素,方法是:
<xsl:output
method="xml" ...
cdata-section-elements="content"
/>
屬性cdata-section-elements
告訴XSLT處理器,元素content
必須寫為CDATA節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.