在忽略大小写的同时获取值时遇到问题。会发生的情况是,当用户输入他们使用的设备数据时,他们可以输入38e135作为设备编号,但稍后他们可以输入38E135。当我遍历设备ID时,我需要将它们视为一个。
当我尝试这个时,我将它们作为两个不同的设备号码。
<xsl:key name="distinctEquipNum" match="//EquipmentNumber" use="."/>
当我尝试使用翻译功能时,我只得到其中一个。
<xsl:key name="distinctEquipNum" match="//EquipmentNumber" use="translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
这是我用来获取数据的循环
<xsl:for-each select=".//EquipmentNumber[generate-id() = generate-id(key('distinctEquipNum', .)[1])]">
<xsl:variable name="equipNum" select="."></xsl:variable>
<td><xsl:value-of select="$equipNum"/></td>
我有办法循环设备号并忽略大小写吗?
以下是我正在使用的XML示例
<Timesheet>
<Equipment>
<EquipmentWorkOrder>
<EquipmentWorkOrderNumber>220923134</EquipmentWorkOrderNumber>
<EquipmentDetail>
<EquipmentMileage>1123</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Bucket truck</EquipmentType>
<EquipmentNumber>38e135</EquipmentNumber>
<MondayHours>6</MondayHours>
<TuesdayHours>Tuesday</TuesdayHours>
<WednesdayHours>1</WednesdayHours>
<ThursdayHours>Thursday</ThursdayHours>
<FridayHours>Friday</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
</EquipmentDetail>
</EquipmentWorkOrder>
<EquipmentWorkOrder>
<EquipmentWorkOrderNumber>220923378</EquipmentWorkOrderNumber>
<EquipmentDetail>
<EquipmentMileage>72155</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>4x4 Pickup</EquipmentType>
<EquipmentNumber>2a3557</EquipmentNumber>
<MondayHours>6</MondayHours>
<TuesdayHours>3</TuesdayHours>
<WednesdayHours>5</WednesdayHours>
<ThursdayHours>2</ThursdayHours>
<FridayHours>Friday</FridayHours>
<SaturdayHours>2</SaturdayHours>
<SundayHours>Sunday</SundayHours>
</EquipmentDetail>
</EquipmentWorkOrder>
<EquipmentWorkOrder>
<EquipmentWorkOrderNumber>220923134</EquipmentWorkOrderNumber>
<EquipmentDetail>
<EquipmentMileage>Mileage</EquipmentMileage>
<EquipmentHourMeter>133</EquipmentHourMeter>
<EquipmentType>Back Hoe</EquipmentType>
<EquipmentNumber>122</EquipmentNumber>
<MondayHours>Monday</MondayHours>
<TuesdayHours>8</TuesdayHours>
<WednesdayHours>3</WednesdayHours>
<ThursdayHours>Thursday</ThursdayHours>
<FridayHours>Friday</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
</EquipmentDetail>
</EquipmentWorkOrder>
<EquipmentWorkOrder>
<EquipmentWorkOrderNumber>220925520</EquipmentWorkOrderNumber>
<EquipmentDetail>
<EquipmentMileage>72155</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Bucket truck</EquipmentType>
<EquipmentNumber>38E135</EquipmentNumber>
<MondayHours>6</MondayHours>
<TuesdayHours>Tuesday</TuesdayHours>
<WednesdayHours>1</WednesdayHours>
<ThursdayHours>Thursday</ThursdayHours>
<FridayHours>Friday</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
</EquipmentDetail>
</EquipmentWorkOrder>
</Equipment></Timesheet>
答案 0 :(得分:2)
您需要将相同的转换应用于您在定义时使用的检索的值,即如果键是
<xsl:key name="distinctEquipNum" match="EquipmentNumber"
use="translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
然后,Muenchian分组表达式需要执行相同的translate
<xsl:for-each select=".//EquipmentNumber[generate-id() =
generate-id(key('distinctEquipNum',
translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')
)[1])]">
(请注意,您在密钥的//
表达式中不需要match
,只需使用match="EquipmentNumber"
)