2

Amend_Start_Dateサンプル XML (MS InfoPath から) から「最新」を返すように、次の XPath 式を調整する必要があります。

//my:Amend_Data[0=count(following-sibling::my:Amend_Data)]//my:Amend_Start_Date

そしてXML:

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.440" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\1c02663d7ed84d09\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><?mso-infoPath-file-attachment-present?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-05-05T19:56:08" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:MasterSection>
    <my:Planning_Section>
        <my:Planned_Start_Date>2012-09-12</my:Planned_Start_Date>
        <my:Planned_End_Date>2012-09-14</my:Planned_End_Date>
    </my:Planning_Section>
    <my:Actual_Section>
        <my:Actual_Start_Date>2012-09-13</my:Actual_Start_Date>
        <my:Actual_End_Date>2012-09-15</my:Actual_End_Date>
    </my:Actual_Section>
    <my:Amend_Hider>
        <my:Amend_Info_Repeater_Group>
            <my:Amend_Info_Repeater>
                <my:Amend_Data>
                    <my:Amend_Start_Date>2012-09-16</my:Amend_Start_Date>
                    <my:Amend_End_Date>2012-09-21</my:Amend_End_Date>
                </my:Amend_Data>
            </my:Amend_Info_Repeater>
            <my:Amend_Info_Repeater>
                <my:Amend_Data>
                    <my:Amend_Start_Date>2012-09-23</my:Amend_Start_Date>
                    <my:Amend_End_Date>2012-09-27</my:Amend_End_Date>
                </my:Amend_Data>
            </my:Amend_Info_Repeater>
        </my:Amend_Info_Repeater_Group>
    </my:Amend_Hider>
</my:MasterSection>

私は先週の木曜日に XPath を使い始めました。現状では、リストされた式はサンプル XML からすべての開始日ノードを返します。「最新」を返すことを意図していますが、ノードがグループ化されていないAmend_Start_Dateような XML の構造であるため、返されません。Amend_Start_Dateこの例では、正しい式が開始日を返し、NOT を返すことを意味し2012-09-23ます 2012-09-16

これを達成できる方法があるに違いありません!どういうわけか、ノードの相対パスをAmend_Data変更する必要があります...どんな助けも大歓迎です!

PS:これは、私が金曜日に投稿した質問に関連しています。その質問とこの質問にリストされているサンプル XML の構造上の違いに気付くかもしれません。

4

3 に答える 3

3

これ:

(//my:Amend_Data)[last()]//my:Amend_Start_Date 

トリックを行う必要があります。

使用せずlast()に試すことができます:

//my:Amend_Info_Repeater[0=count(following-sibling::my:Amend_Info_Repeater)]/my:Amend_Data/my:Amend_Start_Date 
于 2012-09-11T19:10:20.817 に答える
1

使用:

(//my:Amend_Start_Date)[last()]

my:Amend_Start_Dateこれにより、XML ドキュメント内のすべての要素の最後 (ドキュメント順) が選択されます。

更新

InfoPath の XPath 実装のバグ/非準拠が原因で、上記の式を正常に/正しく評価できない場合は、次のことを試してください。

//my:Amend_Start_Date
    [not(preceding::my:Amend_Start_Date or ancestor::my:Amend_Start_Date)]
于 2012-09-12T13:02:47.273 に答える
0

1 つの xpath には入っていませんが、xslt が役立つかもしれません。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-05-05T19:56:08">
    <xsl:output method = "text" indent="yes"/>

    <xsl:variable name="y" select="//my:Amend_Data"/>
    <xsl:variable name="x" select="$y[count($y)]/my:Amend_Start_Date"/>

  <xsl:template match="/">
        <xsl:value-of select="$x"/>
  </xsl:template>
</xsl:stylesheet>
于 2012-09-11T18:41:21.633 に答える