Xml XSLT current()不起作用

Xml XSLT current()不起作用,xml,xslt,xpath,Xml,Xslt,Xpath,我创建了以下XML <Shipment> <ShipmentHeader> <Welcome>HI</Welcome> </ShipmentHeader> <ShipmentStop> <StopSequence>STOP1</StopSequence> <ShipmentStopDetail> <Try>

我创建了以下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>
预期的结果是

<?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>
我的逻辑是我需要绘制的每一个ShipmentStop细节 该值必须从当前ShipmentStop/StopSequence中选取

这可以非常简单地通过以下方式实现:

XSLT1.0

致:


你期望发生什么?current返回当前上下文节点,此时该节点将是正在处理的ShipmentStopDetail节点。您在这里试图实现什么?预期结果是什么,为什么?@Matthew实际上上下文节点是ShipmentStopDetail-但由于表达式在括号中,它将位置步骤引用为其上下文节点。大家好,我添加了预期结果,为什么xpath返回空值?@SatheeshKumar请解释实现结果的逻辑。最好编辑您的示例,这样字符串就不会重复了。谢谢,如果我想打印OTP,那么使用STOP1需要什么Xpath,我有点怀疑OP@SatheeshKumar对不起,我没听懂。我建议你编辑你的问题,并解释清楚你想要什么。
<?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>
<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>
<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>