我有一个由这个脚本转换的 xml:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="LogDataExport/logdata"/>
</xsl:template>
<!-- Build your output file, set date and time and then recurse the rest
of input doc -->
<xsl:template match="logdata">
<xsl:copy>
<xsl:element name="Date">
<!-- Grab the Date/Time from the first LogDataSet/t element -->
<xsl:value-of select="substring-before(LogDataSet[1]/t,'T')"/>
</xsl:element>
<xsl:element name="Time">
<xsl:value-of select="substring-after(LogDataSet[1]/t,'T')"/>
</xsl:element>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- For each name element in LogDataSet create an element with that value
and set the value to the content of the value element -->
<xsl:template match="LogDataSet">
<!-- remove spaces and % symbol from name value -->
<xsl:element name="{translate(translate(translate(name,' ',''),'%','P'),'ü','u')}">
<xsl:value-of select="value"/>
</xsl:element>
</xsl:template>
<!-- Identity template recurse input document elements and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
输出如下所示:
<logdata><Date>2013-04-13</Date><Time>01:04:18.329</Time>
<Sensor1>26.45</Sensor1>
<Sensor2>48.24</Sensor2>
<aquaeroCPU>33.14</aquaeroCPU>
<Flow1>162.2</Flow1>
<Flow2>152</Flow2>
<Fan2>892</Fan2>
<Fan3>900</Fan3>
<Fan4>877</Fan4>
<FullstandinP>80</FullstandinP>
<Wassertemperatur>28.76</Wassertemperatur>
<Pumpe>87.852875717465153</Pumpe>
<Pumpe>12.147540983606557</Pumpe>
<Pumpe>0.584</Pumpe>
<Pumpe>5271.1725430479091</Pumpe>
</logdata>
您会看到最后 4 个名称都相同。
我怎样才能得到名称后面的数字,例如:
<Pumpe1>
<Pumpe2>
<Pumpe3>
...
或者是否可以从原始 xml 中的其他两个名称生成一个名称:
<LogDataSet>
<t>2013-04-13T01:08:47.751</t>
<value>0.5696</value>
<name>Pumpe</name>
<unit>A</unit>
<valueType>current</valueType>
<device>aquastream xt</device>
</LogDataSet>
this should transformed to <Pumpe-current> aka <xsl:element name="name" - "valueType">
谢谢你
麦克风