XML 목차가 있습니다. 각 XML 앵커 지점 목록에서 명명 된 .xhtml 페이지를 생성하고 있습니다.중첩 된 항목 목록의 노드 속성 선택
TOC의 구조에는 해당 장의 하위 절이 나열되어 있습니다. 이전 챕터 앵커의 @href 값을 사용하여 해당 하위 섹션 앵커 이름을 동적으로 지정하려고합니다.
샘플 XML :
<div class="toc" id="s9781483331812.i34"><a class="page" id="pbr-v" title="v"/>
<p class="toc-title">Contents</p>
<ul class="toc">
<li class="toc-item">
<a class="ref-chap" href="#s132" id="s35"><b>Preface</b></a>
<a class="page-ref" href="#pbr-vii" id="s36"><b>vii</b></a>
</li>
<li class="toc-item">
<a class="ref-chap" href="#s135" id="s37"><b>Introduction</b></a>
<a class="page-ref" href="#pbr-xi" id="s38"><b>xi</b></a>
</li>
<li class="toc-item">
<span class="toc-label" title="1"><b>1.</b></span>
<a class="ref-chap" href="#s147" id="s39"><b>Chapter</b></a>
<a class="page-ref" href="#pbr-1" id="s40"><b>1</b></a>
<ul class="chapter-section">
<li class="toc-item">
<a class="ref-chap" href="#s152" id="s41">Subsection 1</a>
<a class="page-ref" href="#pbr-2" id="s42">2</a>
</li>
<li class="toc-item">
<a class="ref-chap" href="#s158" id="s43">Subsection 2</a>
<a class="page-ref" href="#pbr-6" id="s44">6</a>
</li>
<li class="toc-item">
<a class="ref-chap" href="#s159" id="s45">Subsection 3</a>
<a class="page-ref" href="#pbr-10" id="s46">10</a>
</li>
</ul>
</li>
</ul>
샘플 XSLT :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="div[@class='toc']//li[@class='toc-item']">
<xsl:element name="li">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="a[@class='ref-chap']">
<xsl:element name="a">
<xsl:attribute name="href" select="concat(substring-after(@href, '#'),'.xhtml')"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template priority="1" match="ul[@class='chapter-section']//a[@class='ref-chap']">
<xsl:variable name="pagenumber" select="following-sibling::a[@class='page-ref']"/>
<xsl:element name="a">
<xsl:attribute name="href" select="concat(substring-after(ancestor::ul[@class='toc']//li[@class='toc-item']//a[@class='ref-chap'][last()]/@href, '#'),'.xhtml','#page',$pagenumber)"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
내 원하는 출력은 :
<div class="toc" id="s9781483331812.i34">
<a class="page" id="pbr-v" title="v"/>
<p class="toc-title">Contents</p>
<ul class="toc">
<li>
<a href="s132.xhtml"><b>Preface</b></a>
<a class="page-ref" href="#pbr-vii" id="s36"><b>vii</b></a>
</li>
<li>
<a href="s135.xhtml"><b>Introduction</b></a>
<a class="page-ref" href="#pbr-xi" id="s38"><b>xi</b></a>
</li>
<li>
<span class="toc-label" title="1"><b>1.</b></span>
<a href="s147.xhtml"><b>Chapter</b></a>
<a class="page-ref" href="#pbr-1" id="s40"><b>1</b></a>
<ul class="chapter-section">
<li>
<a href="s147.xhtml#page2">Subsection 1</a>
<a class="page-ref" href="#pbr-2" id="s42">2</a>
</li>
<li>
<a href="s147.xhtml#page6">Subsection 2</a>
<a class="page-ref" href="#pbr-6" id="s44">6</a>
</li>
<li>
<a href="s147.xhtml#page10">Subsection 3</a>
<a class="page-ref" href="#pbr-10" id="s46">10</a>
</li>
</ul>
</li>
</ul>
"하나 이상의 항목 시퀀스가 substring-after() ("# s132 ","# s135 ", ...)의 첫 번째 인수로 허용되지 않습니다. 분명히 XPath는 하나가 아닌 여러 값을 선택합니다. 그러나, 나는 이것을 해결하는 방법을 알아낼 수 없습니다.
참고 : 장 서브 섹션 수는 알려져 있지 않으며 다를 수 있습니다.
이것은 내가 찾고있는 정확하게 위대하다. 그러나 밖으로 계산하는 것은 실패한다. 좋은 설명을 주셔서 감사합니다. – user2093335