XSLT <xsl:for-each>元素

时间:2019-03-26 12:52:59

标签: xslt xslt-1.0

输入xml

<?xml version="1.0" encoding="UTF-8"?>
<EAXML xmlns="http://east-adl.info/2.1.12" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://east-adl.info/2.1.12 eastadl_2-1-12.xsd">
  <TOP-LEVEL-PACKAGES>
    <EA-PACKAGE>
      <SHORT-NAME>abc</SHORT-NAME>
      <CATEGORY>1</CATEGORY>
    </EA-PACKAGE>
    <EA-PACKAGE>
      <SHORT-NAME>xyz</SHORT-NAME>
      <CATEGORY>2</CATEGORY>
    </EA-PACKAGE>
  </TOP-LEVEL-PACKAGES>
</EAXML>

必需的输出:

<?xml version="1.0" encoding="UTF-8"?>
<am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.8.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xmi="http://www.omg.org/XMI" xmi:version="2.0">
  <swModel>
    <tasks multipleTaskActivationLimit="1" preemption="preemptive" name="SW_Task"/>
    <tr>
        <td>abc</td>
    </tr>
    <tr>
        <td>xyz</td>
    </tr>
  </swModel>
</am:Amalthea>

XSLT输入:

<?xml version = "1.0" encoding = "UTF-8"?>

<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

<xsl:output method = "xml" indent = "yes" />

<xsl:template match = "/">

<am:Amalthea xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.8.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <swModel>
    <tasks name="SW_Task" preemption="preemptive" multipleTaskActivationLimit="1">
    </tasks>

    <xsl:for-each select="EAXML/TOP-LEVEL-PACKAGES/EA-PACKAGE">
      <tr>
        <td><xsl:value-of select="SHORT-NAME"/></td>
      </tr>
     </xsl:for-each>

  </swModel>

  </am:Amalthea>

  </xsl:template>

  </xsl:stylesheet>

当我尝试运行这些命令时,“ for-each”不起作用,并且我在输出文件中没有获得“ tr”和“ td”元素。我在这里想念什么吗?谢谢!注意:我正在使用xslt_v1.0。

0 个答案:

没有答案