我有一个像这样的xml文件。这可能需要迭代我需要将这个xml文件转换为另一个xml文件,其方式如下所示。因此,我需要生成xslt文件来转换xml文件。
<?xml version="1.0" ?>
- <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test%20schema%20from%20editor.xsd">
<Measures>
<Project>SMFC4B0</Project>
<WorkProduct>Algo Integration Test</WorkProduct>
<Date>41725</Date>
<M14>100</M14>
<M99>10</M99>
<M102>0</M102>
<M100>100</M100>
</Measures>
<Measures>
<Project>ARS 400</Project>
<WorkProduct>System Test</WorkProduct>
<Date>41725</Date>
<M14>100</M14>
<M99>10</M99>
<M102>0</M102>
<M100>100</M100>
</Measures>
<Measures>
------
------
</Measures>
<Measures>
------
------
</Measures>
我想让我的xml像这样
我试图创建一个xslt文件进行转换,它没有用,我看过很多网站和视频,我无法做到。
<?xml version="1.0" ?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test%20schema%20from%20editor.xsd">
<Measures>
<Project>SMFC4B0</Project>
<WorkProduct>Algo Integration Test</WorkProduct>
<Date>41725</Date>
<meashure>
<name>M14</name>
<value>100</value>
</meashure>
<meashure>
<name>M99</name>
<value>10</value>
</meashure>
<meashure>
<name>M102</name>
<value>0</value>
</meashure>
<meashure>
<name>M100</name>
<value>100</value>
</meashure>
</Measures>
<Measures>
<Project>ARS 400</Project>
<WorkProduct>System Test</WorkProduct>
<Date>41725</Date>
<meashure>
<name>M14</name>
<value>100</value>
</meashure>
<meashure>
<name>M99</name>
<value>10</value>
</meashure>
<meashure>
<name>M102</name>
<value>0</value>
</meashure>
<meashure>
<name>M100</name>
<value>100</value>
</meashure>
</Measures>
我希望xslt文件创建此输出。
请任何人都可以提供xslt文件。或者一些有用的材料来编写这个xslt脚本。
答案 0 :(得分:0)
试试这个
<xsl:template match="/">
<Root>
<xsl:for-each select="Root/Measures">
<Measures>
<Project>
<xsl:value-of select="Project"/>
</Project>
<WorkProduct>
<xsl:value-of select="WorkProduct"/>
</WorkProduct>
<Date>
<xsl:value-of select="Date"/>
</Date>
<xsl:variable name="temp" select="Date/following-sibling::*"/>
<xsl:for-each select="$temp">
<meashure>
<name>
<xsl:value-of select="name()"/>
</name>
<value>
<xsl:value-of select="."/>
</value>
</meashure>
</xsl:for-each>
</Measures>
</xsl:for-each>
</Root>
</xsl:template>