5

この質問と同様の問題: XPath: select a node based on another node?

オブジェクトは、兄弟ノードの値に基づいてノードを選択することです。この場合は、Pagetype ノードの値に基づいて Pagetitle ノードです。

xpath:

/dsQueryResponse/Rows/Row/@Title
/dsQueryResponse/Rows/Row/@Pagetype
/dsQueryResponse/Rows/Row/@Pagetitle

この xsl は何も返していません:

<xsl:value-of select= "/dsQueryResponse/Rows/Row[Pagetype='Parent']/@Pagetitle" />  

サンプル XML:

<dsQueryResponse>
       <Rows>
            <Row>
               <Title>1</Title>
               <Pagetype>Parent</Pagetype>
               <Pagetitle>title of page</Pagetitle>
            </Row>
        </Rows>
</dsQueryResponse>  

目標は、Pagetype 値が「Parent」の場合に Pagetitle の値を返すことです。

4

3 に答える 3

3

@ 記号は、ノードの属性を示します。したがって、Pagetype 属性が Parent と等しい Pagetitle 属性の値を返したい場合は、次のようにする必要があります。

<xsl:value-of select= "/dsQueryResponse/Rows/Row[@Pagetype='Parent']/@Pagetitle" />

XPATH をテストするために使用する役立つリソースは、http: //www.xmlme.com/XpathTool.aspx です。

于 2011-10-19T17:27:02.403 に答える
0

提供された XML ドキュメントでは、次を使用します

/*/*/*[Pagetype = 'Parent']/Pagetitle

XSLT ベースの検証:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select="/*/*/*[Pagetype = 'Parent']/Pagetitle"/>
 </xsl:template>
</xsl:stylesheet>

この変換が提供された XML ドキュメントに適用される場合:

<dsQueryResponse>
       <Rows>
            <Row>
               <Title>1</Title>
               <Pagetype>Parent</Pagetype>
               <Pagetitle>title of page</Pagetitle>
            </Row>
        </Rows>
</dsQueryResponse>

XPath 式が評価され、選択されたすべてのノード (この場合は 1 つだけ) が出力されます

<Pagetitle>title of page</Pagetitle>
于 2011-10-20T03:10:27.460 に答える