使用XSLT循环遍历XML中的属性列表
我有以下问题:使用XSLT循环遍历XML中的属性列表,xml,xslt,Xml,Xslt,我有以下问题: 200-2131 视觉的 通过 26/01/2020 13:08:51 200-2131 R iso 通过 26.01.2020 13:08:56 525V 199.9 MOhm 2.00 MOhm AOAB 1.6.10 500伏 3秒 里索-S 200-2131 接触泄漏 通过 26.01.2020 13:09:28 1.59千瓦 0.001毫安 0.50毫安 AOAB 1.6.10 10秒 对 5秒 200-2131 功能的 通过 26/01/2020 13:09:43
200-2131
视觉的
通过
26/01/2020 13:08:51
200-2131
R iso
通过
26.01.2020 13:08:56
525V
199.9 MOhm
2.00 MOhm
AOAB
1.6.10
500伏
3秒
里索-S
200-2131
接触泄漏
通过
26.01.2020 13:09:28
1.59千瓦
0.001毫安
0.50毫安
AOAB
1.6.10
10秒
对
5秒
200-2131
功能的
通过
26/01/2020 13:09:43
在此数据集中,始终存在4个值:
结构路径
测量名称
状态名
P_日期时间
我希望XSLT创建以下内容:
由于其他属性是半变量,因此每个度量的属性名称都不是标准的或相同的。我想选择重复出现的属性,并在1字段中包含其他值。我就是不能让它工作
这是我迄今为止创建的XSLT:
在拉式样式转换之后,此样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/*">
<Data>
<xsl:for-each select="Measurements">
<xsl:variable name="others"
select="*[not(self::StructurePath
|self::P_DateTime
|self::MeasurementName
|self::StatusName)]"/>
<Object Type="_MetrelValues" Action="InsertOrSkip">
<Property Name="Equipment" Value="{StructurePath}"/>
<Property Name="MeasurementPoint" Value="METRELMI3360"/>
<Property Name="Date" Value="{P_DateTime}"/>
<Property Name="Name" Value="{MeasurementName}"/>
<Property Name="MeasureStatus" Value="{StatusName}"/>
<xsl:if test="$others">
<Property Name="ConcatValues">
<xsl:attribute name="Value">
<xsl:for-each select="$others">
<xsl:value-of select="."/>
<xsl:if test="position()!=1">
<xsl:value-of select="' '"/>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</Property>
</xsl:if>
</Object>
</xsl:for-each>
</Data>
</xsl:template>
</xsl:stylesheet>
输出:
<Data>
<Object Type="_MetrelValues" Action="InsertOrSkip">
<Property Name="Equipment" Value="200-2131"/>
<Property Name="MeasurementPoint" Value="METRELMI3360"/>
<Property Name="Date" Value="26/01/2020 13:08:51"/>
<Property Name="Name" Value="Visual"/>
<Property Name="MeasureStatus" Value="Pass"/>
</Object>
<Object Type="_MetrelValues" Action="InsertOrSkip">
<Property Name="Equipment" Value="200-2131"/>
<Property Name="MeasurementPoint" Value="METRELMI3360"/>
<Property Name="Date" Value="26.01.2020 13:08:56"/>
<Property Name="Name" Value="R iso"/>
<Property Name="MeasureStatus" Value="Pass"/>
<Property Name="ConcatValues"
Value="525 V>199.9 MOhm 2.00 MOhm AOAB 1.6.10 500 V 3 s Riso-S "/>
</Object>
<Object Type="_MetrelValues" Action="InsertOrSkip">
<Property Name="Equipment" Value="200-2131"/>
<Property Name="MeasurementPoint" Value="METRELMI3360"/>
<Property Name="Date" Value="26.01.2020 13:09:28"/>
<Property Name="Name" Value="Touch Leakage"/>
<Property Name="MeasureStatus" Value="Pass"/>
<Property Name="ConcatValues"
Value="1.59 kW0.001 mA 0.50 mA AOAB 1.6.10 10 s YES 5 s "/>
</Object>
<Object Type="_MetrelValues" Action="InsertOrSkip">
<Property Name="Equipment" Value="200-2131"/>
<Property Name="MeasurementPoint" Value="METRELMI3360"/>
<Property Name="Date" Value="26/01/2020 13:09:43"/>
<Property Name="Name" Value="Functional"/>
<Property Name="MeasureStatus" Value="Pass"/>
</Object>
</Data>
尽管您可能认为这些东西是“属性”,但这个词在XML中有不同的含义,您实际上是在谈论元素。