从XML创建XSLT以获得所需的XML

时间:2020-12-28 09:48:43

I have a situation here : Consider the following code as example :

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

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

Now here I need to design an XSLT which will create elements having data from element where alias is abc, bcd simultaenously whose output will be something like this :

现在我需要设计一个XSLT,它将创建元素中包含数据的元素,其中别名是abc,bcd simultaenously其输出将是这样的:

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

1 个解决方案

#1


0  

You need to use the xsl:output element at the top of the stylesheet to list the elements you need as CDATA, this way:

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

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

The attribute cdata-section-elements tells the XSLT processor that the element content must be written as a CDATA section.

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

#1


0  

You need to use the xsl:output element at the top of the stylesheet to list the elements you need as CDATA, this way:

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

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

The attribute cdata-section-elements tells the XSLT processor that the element content must be written as a CDATA section.

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