Я пытаюсь отобразить количество страниц в документе, взяв значение @n
последнего <pb/>
в документе. Прямо сейчас, я все еще получаю значение первого <pb/>
. Вот мой вклад XML:Выбор значения атрибута последнего элемента
<p><line>While a prisoner here remains in their</line>
<line>so-called 1st grade, he is able to write</line>
<line>twice a week, in second grade once a week,</line>
<line>and in third grade once a month. These</line>
<line>grades refer to classifications that ostensibly</line>
<line>are for conduct while here. It is quite possible</line>
<line>to lose a conduct rating, as I understand it,</line>
<line>by not having a perpetually rusting tin cup polished</line>
<pb n="2"/>
<line>brightly for daily inspection, although the tin plating long ago dis-</line>
<line>appeared and the cup is rusty again within 2 hours after wetting.</line></p>
<p><line>The food here is good and is well-cooked,</line>
<line>with one exception, the gravy, which is nothing but</line>
<line>flour, water, and bacon grease, Strangely enough, how-</line>
<line>ever, no condiments, not even salt, are provided on</line>
<pb n="3"/>
<line>the table, to the detriment of otherwise very good</line>
<line>meals. While meat here is unrationed and is plentiful,</line>
<line>toilet paper; believe it or not, is rationed. A</line>
<line>5¢ roll must last a prisoner 45 days, or else -- ?</line>
<line>Perhaps, however, a prisoner can purchase additional</line>
<line>if it should be necessary.</line></p>
А вот мой XSL:
<dt>Pages:</dt>
<dd>
<xsl:if test="//pb">
<xsl:value-of select="//pb[position()=last()]/@n"/>
</xsl:if>
</dd>
Как я могу выбрать значение @n
последнего <pb/>
во всем документе?
На самом деле я думаю, что это правильно. Вы можете попробовать '(// pb/@ n) [last()]' вместо этого, но я не понимаю, почему ваш xpath не должен работать. Может быть, вы можете предоставить некоторые из ваших html-кодов? – spcial
Добавил xml, который я и трансформировал. – Misenus
@Misenus XML, который вы показываете, не является корректным, поэтому бесполезным. –