我在for-each
中使用了XSLT
。在我的示例XML
中,我只有一个元素,但for-each执行了13次,我无法弄清楚原因。
XSLT
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<rowset>
<xsl:for-each select="OUTPUT/eas:ShowDetailedRequestsByScheduleId/eas:ScheduleRequest">
<xsl:variable name="status"/>
<test>
<xsl:value-of select="@Schedule"/>
</test>
</xsl:for-each>
</rowset>
</xsl:template>
</xsl:stylesheet>
XML输入
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<OUTPUT xmlns:eas="****************">
<eas:ShowDetailedRequestsByScheduleId>
<eas:ScheduleRequest PPR="" Schedule="New Standard Drum Filling Orders" createdBy="" createdOn="2014-05-03 01:14:06.973" endTime="" isaDescription="" isaId="50527" lastModifiedBy="" lastModifiedOn="" priority="1" startTime="">
<eas:SegmentRequirement ScheduleRequest="50527" createdBy="root" createdOn="2014-05-03 01:14:06.973" duration="" durationUnitOfMeasure="" endTime="" isaDescription="" isaId="DF_FIlling" lastModifiedBy="root" lastModifiedOn="2014-05-03 01:14:06.973" startTime="">
<eas:MaterialProducedRequirement createdBy="root" createdOn="2014-05-03 01:14:06.977" isaDescription="" isaId="" lastModifiedBy="root" lastModifiedOn="2014-05-03 01:14:06.977" location="" materialDefinition="51014-302" quantity="5.000000000000" quantityUnitOfMeasure=""/>
</eas:SegmentRequirement>
</eas:ScheduleRequest>
</eas:ShowDetailedRequestsByScheduleId>
</OUTPUT>
XML输出
<?xml version="1.0" encoding="UTF-8"?>
<rowset>
<test />
<test />
<test />
<test />
<test>New Standard Drum Filling Orders</test>
<test />
<test />
<test />
<test />
<test />
<test />
<test />
<test />
</rowset>
答案 0 :(得分:1)
名称空间也需要在XML和XSLT中定义。目前XSLT中缺少它:
XSLT:
<?xml version="1.0" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eas="****************">
<!-- ... --->
</xsl:stylesheet>
XML输入:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<OUTPUT xmlns:eas="****************">
<eas:ShowDetailedRequestsByScheduleId>
<!-- ... --->
</eas:ShowDetailedRequestsByScheduleId>
</OUTPUT>