0

我这里有一个情况:考虑以下代码作为示例:

    <?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..??
4

1 回答 1

0

您需要使用样式表顶部的 xsl:output 元素来列出您需要作为 CDATA 的元素,这样:

<xsl:output
method="xml" ...
cdata-section-elements="content"
/>

该属性cdata-section-elements告诉 XSLT 处理器该元素content必须写为 CDATA 部分。

于 2013-08-26T22:30:14.643 回答