1
我有下面的XML:XML使用XML XSLT来 - 变换多个节点
<EMPLOYEE_LIST>
<EMPLOYEES>
<PERMANENT>
<EMPID>650000</EMPID>
<FIRST_NAME>KEITH</FIRST_NAME>
<MIDDLE_NAME>H</MIDDLE_NAME>
<LAST_NAME>ROGERS</LAST_NAME>
</PERMANENT>
<CONTRACTUAL>
<EMPID>650001</EMPID>
<FIRST_NAME>DARRYL</FIRST_NAME>
<MIDDLE_NAME>Y</MIDDLE_NAME>
<LAST_NAME>HANNAH</LAST_NAME>
</CONTRACTUAL>
</EMPLOYEES>
</EMPLOYEE_LIST>
它给了我所提到的下输出:
:<?xml version="1.0" encoding="UTF-8"?>
<employees>
<permanent>
<emp_id>650000</emp_id>
<f_name>KEITH</f_name>
<m_name>H</m_name>
<l_name>ROGERS</l_name>
</permanent>
<contractual>
<emp_id>650001</emp_id>
<f_name>DARRYL</f_name>
<m_name>Y</m_name>
<l_name>HANNAH</l_name>
</contractual>
</employees>
当使用这种XSLT转换
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/EMPLOYEE_LIST">
<employees>
<xsl:apply-templates select="EMPLOYEES/node()"/>
</employees>
</xsl:template>
<xsl:template match="PERMANENT">
<permanent>
<xsl:apply-templates select="*"/>
</permanent>
</xsl:template>
<xsl:template match="EMPID">
<emp_id>
<xsl:value-of select="."/>
</emp_id>
</xsl:template>
<xsl:template match="FIRST_NAME">
<f_name>
<xsl:value-of select="."/>
</f_name>
</xsl:template>
<xsl:template match="MIDDLE_NAME">
<m_name>
<xsl:value-of select="."/>
</m_name>
</xsl:template>
<xsl:template match="LAST_NAME">
<l_name>
<xsl:value-of select="."/>
</l_name>
</xsl:template>
<xsl:template match="CONTRACTUAL">
<permanent>
<xsl:apply-templates select="*"/>
</permanent>
</xsl:template>
<xsl:template match="EMPID">
<emp_id>
<xsl:value-of select="."/>
</emp_id>
</xsl:template>
<xsl:template match="FIRST_NAME">
<f_name>
<xsl:value-of select="."/>
</f_name>
</xsl:template>
<xsl:template match="MIDDLE_NAME">
<m_name>
<xsl:value-of select="."/>
</m_name>
</xsl:template>
<xsl:template match="LAST_NAME">
<l_name>
<xsl:value-of select="."/>
</l_name>
</xsl:template>
</xsl:stylesheet>
这不是我想要实现的,因为我需要将上述XML转换为另一个展示以下的输出:
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<emp_id>650000</emp_id>
<f_name>KEITH</f_name>
<m_name>H</m_name>
<l_name>ROGERS</l_name>
<type>permanent</type>
<emp_id>650001</emp_id>
<f_name>DARRYL</f_name>
<m_name>Y</m_name>
<l_name>HANNAH</l_name>
<type>contractual</type>
</employee>
</employees>
我是新来的XSLT和任何帮助,将
感谢
感谢该做的伎俩,但只是一个简单的问题 - 如果我有EMPLOYEE_LIST/EMPLOYEES_1(有自己的节点)的XML/EMPLOYEES_2(有自己的节点)/EMPLOYEES_3(带有其自己的节点) - 这将是具有相似子节点的3个不同的父节点。我们如何将其转化为上述给定的输出? – 2013-03-02 16:49:04
@ReggieMiller,我很高兴“那样做了”。请,因为这解决了您的问题,请*,接受*这个答案 - 通过点击答案旁边的复选标记。另外,请问任何新的问题......好吧,新的SO问题。这有助于读者和回答者,因为评论格式不适合格式化代码。 – 2013-03-02 16:52:12
按照指示完成。我现在将这个新场景作为另一个问题发布。谢谢 – 2013-03-02 17:00:48