0

最初と2番目の見出しを検索するようにxpathを設定しましたが、2番目の見出しは空白になります。これはかなり簡単だと思いますが、パス名を何度も変更しようとしましたが、解決できないようです。おそらく私のxmlファイルが間違っていたかどうかを調べるために、私のループは両方を簡単に見つけるようです。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="blogschema.xsd"
exclude-result-prefixes="foo">
<xsl:output method ="html" indent ="no"/> 
<xsl:template match="/">
<html>
<link rel ="stylesheet" type="text/css" href="blogStyle.css"/>
    <body>
    <ul class="menu">
    <li><a href="#" class ="Part 1"><xsl:value-of select="//foo:Heading[1]"/> </a></li>
    <li><a href="#" class ="Part 2"><xsl:value-of select="//foo:Heading[2]"/></a></li>
    </ul>






        <div id="heading">

        <xsl:for-each select="//foo:Entry">
        <!--<xsl:sort select="Heading"/> -->


        <div class ="topNavigation"><a href="#home"><h3><xsl:value-of    select="foo:Heading"/></h3></a></div>

        </xsl:for-each>
        <div class ="panes">




        </div>

        </div>
        <div id ="blogpicture">
            <div class="picture">
                <div id="headerTitle"><h2><xsl:value-of        select="//foo:Title"/></h2></div>
                </div>
                </div>


    </body>
    </html>
</xsl:template>
</xsl:transform>

メニューを取得しようとしていますが、現在取得しているのはメニューのパート 1 だけです。for ループではパート 2 を取得できます。代わりに、ループの使用に固執することもできます。ループ中 (クラス ID をインクリメント) My blog

<Entry>
    <Heading id="101">Part 1</Heading>  
    <body>
        <text>something interesting</text>
        <pictures>pictures in the body</pictures>
        <videos>Videos in the body</videos>
    </body>
    <labels>Seperate labels with commas</labels>
    <date> 20121119</date>
    <location>The location the blog was published</location>

</Entry>

<Entry>
    <Heading id="102">Part 2</Heading>
        <body>
            <text>something</text>
            <pictures>pictures in the body</pictures>
            <videos>Videos in the body</videos>
        </body>
    <labels>Seperate labels with commas</labels>
    <date> 2012-11-26Z</date>
    <location>The location the blog was published</location>

</Entry>


<author>me</author>

これが、現在メニュー u に表示されている出力がパート 1 であり、パート 2 が必要な場所の "" であることに何らかの意味があることを願っています。ただし、xsl の for each ループは、パート 1 と 2 の見出しをもたらします。

4

1 に答える 1

3

これはどう:

<li><a href="#" class ="Part 1"><xsl:value-of select="//foo:Entry[1]/foo:Heading"/> </a></li>
<li><a href="#" class ="Part 2"><xsl:value-of select="//foo:Entry[2]/foo:Heading"/></a></li>

あるいは、これもうまくいくはずです:

<li><a href="#" class ="Part 1"><xsl:value-of select="(//foo:Heading)[1]"/> </a></li>
<li><a href="#" class ="Part 2"><xsl:value-of select="(//foo:Heading)[2]"/></a></li>

全能のXPath 仕様から:

//の略です/descendant-or-self::node()/。たとえば、//paraは for の略/descendant-or-self::node()/child::paraで、ドキュメント内の任意の para 要素を選択します (//paraドキュメント要素ノードはルート ノードの子であるため、ドキュメント要素である para 要素でさえも選択されます)。div//paraは for の略でdiv/descendant-or-self::node()/child::paraあり、div の子のすべての para 子孫を選択します。

注: ロケーション パスは、ロケーション パスと同じ意味では//para[1]ありませ/descendant::para[1]。後者は、最初の子孫の para 要素を選択します。前者は、親の最初の para 子であるすべての子孫 para 要素を選択します。

于 2013-01-08T06:37:40.680 に答える