我创建了以下XML
<Shipment>
<ShipmentHeader>
<Welcome>HI</Welcome>
</ShipmentHeader>
<ShipmentStop>
<StopSequence>STOP1</StopSequence>
<ShipmentStopDetail>
<Try>OTP</Try>
</ShipmentStopDetail>
<ShipmentStopDetail>
<Try>OTP</Try>
</ShipmentStopDetail>
</ShipmentStop>
<ShipmentStop >
<StopSequence>STOP2</StopSequence>
<ShipmentStopDetail>
<Try>OTP</Try>
</ShipmentStopDetail>
<ShipmentStopDetail>
<Try>OTP</Try>
</ShipmentStopDetail>
</ShipmentStop>
</Shipment>
这是我的XSLT
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:pfx4='http://xmlns.oracle.com/apps/otm'>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<ZPOINT>
<xsl:for-each select="Shipment">
<xsl:for-each select="ShipmentStop">
<xsl:for-each select="ShipmentStopDetail">
<LSQNUM>
<xsl:value-of select="Shipment/ShipmentStop[current()]/StopSequence[current()]"/>
</LSQNUM>
<Change>
<xsl:value-of select="Shipment/ShipmentStop[current()]/StopSequence[current()]/ShipmentStopDetail[current()]"/>
</Change>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ZPOINT>
</xsl:template>
</xsl:stylesheet>
我正在尝试执行子字符串操作,但输出并不像我预期的那样。 XPath表达式返回null
。有人能帮我吗?我哪里错了?
以下是我的输出
<?xml version="1.0" encoding="UTF-8"?>
<ZPOINT xmlns:pfx4="http://xmlns.oracle.com/apps/otm">
<LSQNUM/>
<LSQNUM/>
<LSQNUM/>
<LSQNUM/>
</ZPOINT>
预期结果是
<?xml version="1.0" encoding="UTF-8"?>
<ZPOINT xmlns:pfx4="http://xmlns.oracle.com/apps/otm">
<LSQNUM>STOP1</LSQNUM>
<Change>OTP<Change>
<LSQNUM>STOP1</LSQNUM>
<Change>OTP<Change>
<LSQNUM>STOP2</LSQNUM>
<Change>OTP<Change>
<LSQNUM>STOP2</LSQNUM>
<Change>OTP<Change>
</ZPOINT>
答案 0 :(得分:0)
我的逻辑是每个ShipmentStopDetail我需要映射
中选择该值<LSQNUM>
和 必须从当前的ShipmentStop / StopSequence
这可以通过以下方式实现:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/Shipment">
<ZPOINT xmlns:pfx4="http://xmlns.oracle.com/apps/otm">
<xsl:for-each select="ShipmentStop/ShipmentStopDetail">
<LSQNUM>
<xsl:value-of select="../StopSequence"/>
</LSQNUM>
</xsl:for-each>
</ZPOINT>
</xsl:template>
</xsl:stylesheet>
<强>结果强>
<?xml version="1.0" encoding="UTF-8"?>
<ZPOINT xmlns:pfx4="http://xmlns.oracle.com/apps/otm">
<LSQNUM>12412412412414</LSQNUM>
<LSQNUM>12412412412414</LSQNUM>
<LSQNUM>123124412412</LSQNUM>
<LSQNUM>123124412412</LSQNUM>
</ZPOINT>
要添加Try
值,请更改:
<xsl:for-each select="ShipmentStop/ShipmentStopDetail">
<LSQNUM>
<xsl:value-of select="../StopSequence"/>
</LSQNUM>
</xsl:for-each>
为:
<xsl:for-each select="ShipmentStop/ShipmentStopDetail">
<LSQNUM>
<xsl:value-of select="../StopSequence"/>
</LSQNUM>
<Change>
<xsl:value-of select="Try"/>
</Change>
</xsl:for-each>