Книга: XSLT

Создание ссылок:

Создание ссылок: <fo:basic-link>

Еще одним мощным средством XSL-FO является возможность использовать ссылки от документа к документу. В данный момент эта возможность поддерживается в процессоре fop при помощи элемента XSL-FO <fo:basic-link>, который действует во многом похоже на обычную гиперссылку. С элементом <fo:basic-link> можно применять следующие свойства:

• общие свойства доступа: source-document, role;

• общие звуковые свойства: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume;

• общие свойства границ, заполнения и заднего фона: background-attachment, background-color, background-image, background-repeat, background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right;

• общие встроенные свойства встроенных полей: space-end, space-start;

• общие свойства относительного расположения: top, right, bottom, left, relative-position;

alignment-adjust;

alignment-baseline;

baseline-shift;

destination-placement-offset;

dominant-baseline;

external-destination;

id;

indicate-destination;

internal-destination;

keep-together;

keep-with-next;

keep-with-previous;

line-height;

line-height-shift-adjustment;

show-destination;

target-processing-context;

target-presentation-context;

target-stylesheet.

Следующий пример, links.fo (листинг 12.6), содержит ссылку на документ PDF, созданный ранее в этой главе, graphics.pdf.

Листинг 12.6. links.fo

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master margin-right="20mm" margin-left="20mm"
   margin-bottom="10mm" margin-top="10mm" page-width="300mm"
   page-height="400mm" master-name="page">
   <fo:region-body margin-right="0mm" margin-left="0mm"
    margin-bottom="10mm" margin-top="0mm"/>
   <fo:region-after extent="10mm"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-name="page">
  <fo:flow flow-name="xsl-region-body">
   <fo:block space-after="12pt" font-weight="bold"
    font-size="36pt" text-align="center">
    Using Links
   </fo:block>
   <fo:block font-size="24pt">
    If you'd like to see some images, click
    <fo:basic-link external-destination="graphics.pdf">
     <fo:inline text-decoration="underline">here</fo:inline>
    </fo:basic-link>.
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

Документ PDF, созданный на основе links.fo, показан на рис. 12.6. Заметьте, что я явно подчеркнул ссылку, чтобы она была больше похожа на гиперссылку. Когда в Adobe Acrobat вы помещаете указатель мыши над ссылкой, он меняет свою форму и становится в точности такой формы, которую Internet Explorer использует для гиперссылок, как показано на рис. 12.6. При щелчке на ссылке Acrobat переходит на graphics.pdf (который для работы примера нужно поместить в тот же каталог, что и links.pdf), отображая этот новый документ.


Рис. 12.6. Поддержка ссылок в XSL-FO 

В данном случае создать ссылку очень просто — достаточно установить свойство external-destination элемента <fo:basic-link> в «graphics.pdf»:

<fo:block font-size="24pt">
 If you'd like to see some images, click
 <fo:basic-link external-destination="graphics.pdf">
  .
  .
  .
 </fo:basic-link>.
</fo:block>

Теперь осталось только добавить подчеркнутый текст, чтобы пользователь мог щелкнуть по нему и перейти к новому документу. Конечно, не обязательно выделять текст подчеркиванием; но иначе ничто не будет указывать на то, что текст является ссылкой, — за исключением указателя мыши, который изменит форму при перемещении над текстом. Подчеркнутый текст можно добавить следующим образом:

<fo:block font-size="24pt">
 If you'd like to see some images, click
 <fo:basic-link external-destination="graphics.pdf">
  <fo:inline text-decoration="underline">here</fo:inline>
 </fo:basic-link>.
</fo:block>

Пока в XSL-FO реализованы только обычные ссылки (basic link), как показано в примере. Но если вы знакомы со спецификациями XML для XPointer и XLink, вам следует ожидать в будущем значительного развития в этой области.

Оглавление книги


Генерация: 0.629. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз