私はこのスクリプトによって変換される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 の他の 2 つの名前から名前を生成することは可能ですか。
<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">
ありがとうございました
マイク