I have an xslt-script that transforms a tei:bibl Element to HTML
<xsl:template match="tei:bibl//tei:author">
<span class="smallcaps">
<xsl:apply-templates select="tei:surname"/>
</span>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="tei:forename"/>
<xsl:if test="tei:nameLink">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:nameLink"/>
</xsl:if>
<xsl:apply-templates select="text()"/>
<xsl:text>, </xsl:text>
<xsl:if test=".[following-sibling::tei:author]">
<xsl:text> / </xsl:text>
<span class="smallcaps">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:surname"/>
</span>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="tei:forename"/>
<xsl:if test="tei:nameLink">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:nameLink"/>
</xsl:if>
<xsl:text> , </xsl:text>
</xsl:if>
</xsl:template>
The XML looks like this:
<bibl xml:id="capitani_ua_bannerherr">
<abbr>
<surname type="author">Capitani</surname> u.a., Bannerherr</abbr>
<author>
<forename>François</forename>
<nameLink>de</nameLink>
<surname>Capitani</surname>
</author>
<author>
<surname>Weck</surname>
<forename>Hervé</forename>
<nameLink>de</nameLink>
</author>
<title>Bannerherr [Venner]</title>
<bibl>
<title>Historisches Lexikon der Schweiz (HLS)</title>
<date>Version vom 07.05.2009</date>
</bibl>
<ref target="http://www.hls-dhs-dss.ch/textes/d/D8612.php" type="ex">[Online]</ref>
</bibl>
My HTML is like this:
<span id="capitani_ua_bannerherr" class="rs-ref">
<span class="smallcaps">Capitani</span>, François de, /
<span class="smallcaps"> Capitani</span>, François de ,
<span class="smallcaps">Weck</span>, Hervé de, Bannerherr [Venner], in: Historisches Lexikon der Schweiz (HLS), Version vom 07.05.2009<a href="http://www.hls-dhs-dss.ch/textes/d/D8612.php"> [Online]
</a>.
</span>
The template does as it is supposed to. However, It doubles the first entry (here <span class="smallcaps"> Vapitani </span>, Francois de, )
I have tried adding an <xsl:choose> that looks like this:
<xsl:template match="tei:bibl//tei:author">
<xsl:choose>
<xsl:when test="[count(tei:bibl//tei:author)=1]">
<span class="smallcaps">
<xsl:apply-templates select="tei:surname"/>
</span>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="tei:forename"/>
<xsl:if test="tei:nameLink">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:nameLink"/>
</xsl:if>
<xsl:apply-templates select="text()"/>
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test=".[following-sibling::tei:author]">
<xsl:text> / </xsl:text>
<span class="smallcaps">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:surname"/>
</span>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="tei:forename"/>
<xsl:if test="tei:nameLink">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:nameLink"/>
</xsl:if>
<xsl:text> , </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
This should produce output like this:
<span id="capitani_ua_bannerherr" class="rs-ref">
<span class="smallcaps">Capitani</span>, François de, /
<span class="smallcaps">Weck</span>, Hervé de, Bannerherr [Venner], in: Historisches Lexikon der Schweiz (HLS), Version vom 07.05.2009<a href="http://www.hls-dhs-dss.ch/textes/d/D8612.php"> [Online]
</a>.
</span>
What am I doing wrong?
I am not looking for any specific version of XSLT, we can use XSLT 1 -3.
all the best,
K
Your current template says "if there is a following author, output the surname and forename". It does not say "output the surname and forename of the following author".
I'm not 100% sure, but you seem to want the following:
a list of authors per <tei:bib>
2nd author separated from the first with /
any further author separated with ,
Let's write that down exactly like that:
<xsl:template match="tei:bibl//tei:author">
<xsl:if test="position() = 2"> / </xsl:if>
<xsl:if test="position() > 2"> , </xsl:if>
<span class="smallcaps">
<xsl:apply-templates select="tei:surname" />
</span>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="tei:forename" />
<xsl:if test="tei:nameLink">
<xsl:text> </xsl:text>
<xsl:apply-templates select="tei:nameLink" />
</xsl:if>
</xsl:template>
Now you can invoke that in a straight-forward manner
<xsl:template match="tei:bibl">
<xsl:apply-templates select="tei:author" />
<!-- ...output the title etc here --->
</xsl:template>
and get (formatted for readability):
<span xmlns:tei="tei" class="smallcaps">Capitani</span>, François de
/ <span xmlns:tei="tei" class="smallcaps">Weck</span>, Hervé de
Related
I want to show the property of tag Page, like this xml:
<format class="Book">BookTitle </format>Test <page number="51" />….... </p>
I have this xslt for convert xml to html
<xsl:template match="format" name="format">
<xsl:choose>
<xsl:when test="name() = 'format'" >
<xsl:if test ="#class = 'q'">
<xsl:call-template name="q" />
</xsl:if>
<xsl:if test ="#class = 'Book'">
<xsl:call-template name="Book" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Book" name=" Book">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="page" name="page">
<xsl:value-of select="#number" />
</xsl:template>
But, attribute of tag Page is not displayed, because this tag is as child of tag Book
What should I do?
<xsl:template match="Book" name=" Book">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="page" name="page">
<xsl:value-of select="#number" />
</xsl:template>
Change to
<xsl:template match="Book" name=" Book">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="page" name="page">
<xsl:value-of select=" #number"/>
</xsl:template>
pls check the below code. I am matching the list element and as per the below code the position() function returns correct number of the element with in ul elements i.e 1,2,3 where as if i do the test with position i get only ss,ss,ss . Can anyone let me know where am missing ?
XSL-FO
<xsl:template match="html:li" priority="2">
<fo:list-item>
...
<xsl:value-of select="position()"/> -- this returns 1,2,3
<xsl:if test="position() = 1">
<xsl:text>ss</xsl:text> -- only executes
</xsl:if>
<xsl:if test="position() = 2">
<xsl:text>ssddddd</xsl:text> -- does not only execute
</xsl:if>
<xsl:if test="position() = 3">
<xsl:text>sskkkkkkkkk</xsl:text> -- does not only execute
</xsl:if>
</fo:list-item>
</xsl:template
XSL
<xsl:template match="list">
<xsl:if test="list.item">
<xsl:variable name="styleAttr">
<xsl:text>margin-top: 1em;</xsl:text>
</xsl:variable>
<div>
<xsl:if test="string-length($styleAttr) > 0">
<xsl:attribute name="style">
<xsl:value-of select="$styleAttr"/>
</xsl:attribute>
</xsl:if>
<ul>
<xsl:apply-templates select="node()[not(self::list)]" />
</ul>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="list.item" priority="1">
<li style="padding: 0;">
<div style="margin-bottom: 0.5em;">
<xsl:apply-templates />
<xsl:if test="following-sibling::node()[1][self::list]">
<xsl:apply-templates select="following-sibling::node()[1]" />
</xsl:if>
</div>
</li>
</xsl:template>
I've the below XML.
<section level="sect1">
<title num="1.3"><content-style font-style="bold">Common Breaches</content-style></title>
<page num="9"/>
<section level="sect2">
<title><content-style font-style="bolditalic">Non-payment of Rent/Service Charge/Hiring Charge/Licence Fee</content-style></title>
<orderedlist type="manual">
<item num="1.3.1"><para>The most common breach in a Tenancy Agreement is the late payment or non payment of rent. The Tenancy Agreement usually provides for the right of the Landlord to re-enter the premises and determine the tenancy upon non-payment of rent for a period of time. This is in addition to the Landlord's rights to sue the Tenant for any outstanding rent and any monies owing under the tenancy up to the expiry of the tenancy and forfeit the security deposit.</para></item>
<item num="1.3.2"><para>The Landlord may commence what are known as Writ of Distress proceedings or Writ of Summons proceedings to claim for the unpaid rent. The Writ of Distress is the more effective remedy, however only rent may be recovered under the Writ of Distress.</para></item>
</orderedlist>
</section>
and i'm using the below XSLT.
<xsl:template name="section" match="section">
<!-- Variables-->
<xsl:variable name="classname">
<!--Get name attribute of current node -->
<xsl:value-of select="concat('section-',#level)"/>
</xsl:variable>
<xsl:variable name="size">
<xsl:value-of select="string-length(ancestor::chapter[1]/#num)"/>
</xsl:variable>
<xsl:variable name="Chn">
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:choose>
<xsl:when test="$size=1">
<xsl:value-of select="concat('0',$Chn)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Chn"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:number level="any" count="section" format="1"/>
</xsl:variable>
<!--Create a string variable by concat string method -->
<xsl:variable name="sectionname">
<xsl:value-of select="concat('CH_',$chapternumber,'-SEC-', $sectnum)"/>
</xsl:variable>
<!-- Template Content -->
<xsl:if test="./page[1]">
<xsl:apply-templates select="./page[1]"/>
</xsl:if>
<div class="{$classname}">
<a name="{$sectionname}"> </a>
<div class="section-title">
<xsl:if test="not(contains(./#num,'unnumbered'))">
<xsl:if test="./title/#num">
<span class="section-num">
<a name="{concat('P',translate(./title/#num,'.','-'))}"></a>
<xsl:value-of select="./title/#num"/>
</span>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="./title/child::node()[fn:not(self::page)]"/>
</div>
<!--<xsl:apply-templates select="child::node()[not(self::title)]"/>-->
</div>
</xsl:template>
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#num">
<xsl:choose>
<xsl:when test="child::node()[1][self::*]">
<xsl:apply-templates select="child::page[1]"/>
<div class="para">
<xsl:call-template name="phrase"/>
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:call-template name="phrase"/>
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(3)) < number(9)">
<a href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/','MCCL_CH_',format-number(number(regex-group(3)),'00'))}">
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="[Pp]aragraphs\s([0-9]+)\.([0-9]+)\sand\s([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(1)) < number(9)">
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="substring-before(., ' and')"/>
</a>
<xsl:text> and </xsl:text>
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/P',format-number(number(regex-group(3)),'0'),'-',format-number(number(regex-group(4)),'000'))}">
<xsl:value-of select="substring-after(., 'and ')"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="[Pp]aragraph\s([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(1)) < number(9)">
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="."></xsl:value-of>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="http://[^ ]+">
<xsl:matching-substring>
<a href="{.}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="orderedlist" match="orderedlist">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="item">
<xsl:choose>
<xsl:when test="not(ends-with(#num, '.')) and fn:contains(#num,'.')">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<li class="item">
<xsl:apply-templates/>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="orderitempara" match="item/para">
<xsl:choose>
<xsl:when test="contains(../../#type,'manual')">
<div class="para">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:choose>
<xsl:when test="contains(parent::item[1]/#num,'bull')">
<xsl:text>•</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="not(ends-with(../#num, '.')) and fn:contains(../#num,'.')">
<xsl:call-template name="phrase"/>
</xsl:when>
<xsl:when test="../#num">
<span class="item-num">
<xsl:apply-templates select="parent::item[1]/#num"/>
</span>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:when>
<xsl:otherwise>
<span class="bullet-list">
<xsl:value-of select="../../#type"/>
</span>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="page">
<xsl:processing-instruction name="pb">
<xsl:text>label='</xsl:text>
<xsl:value-of select="./#num"/>
<xsl:text>'</xsl:text>
<xsl:text>?</xsl:text>
</xsl:processing-instruction>
<a name="{concat('pg_',./#num)}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="phrase">
<xsl:choose>
<xsl:when test="parent::title">
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',#num)"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<span class="phrase1">
<xsl:value-of select="current()"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',../#num)"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<span class="phrase">
<xsl:value-of select="../#num"/>
</span>
</xsl:otherwise>
</xsl:choose>
<!--<xsl:apply-templates/>-->
</xsl:template>
when i run this i'm getting output as below.
here the processing instruction number 9 (pb label='9') is getting duplicated, please let me know how can i get the below output.
Thanks
have your page template in a different mode
<xsl:apply-templates select="page[1]" mode="insert_page"/>
and
<xsl:template match="page" mode="insert_page">
I've the below piece of XML.
<section level="sect2" number-type="manual">
<para align="center">
<phrase>24-2</phrase>
<content-style font-style="italic">Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.</content-style>
</para>
</section>
and when i apply the below XSLT
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align=center and ./#differentiation">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align=center and not(./#differentiation)">
<div class="para align1-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align and ./phrase[1]">
<div class="para new">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
<xsl:matching-substring>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:variable name="num">
<xsl:value-of select="string-length(regex-group(2))"/>
</xsl:variable>
<a
href="{concat('er:#ABHK_CH_',format-number(number(regex-group(2)),'00'),'/P',format-number(number(regex-group(2)),'0'),'-',regex-group(3))}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<xsl:variable name="phrl">
<xsl:value-of select="string-length(text())"/>
</xsl:variable>
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',text())"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<xsl:choose>
<xsl:when test="../#align">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<span class="align-center">
<xsl:apply-templates select="following-sibling::node()[1]"/>
</span>
</xsl:when>
<xsl:when test="$phrl=3">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<xsl:text disable-output-escaping="yes">        </xsl:text>
</xsl:when>
<xsl:when test="$phrl=4">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<xsl:text disable-output-escaping="yes">    </xsl:text>
</xsl:when>
<xsl:otherwise>
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="./#format">
<span class="{concat('format-',#format)}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:choose>
<xsl:when test="../#align">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
<xsl:apply-templates select="para"/>
</xsl:otherwise>
</xsl:choose>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
the output i get is
24-2 Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong. Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.
here Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.
is getting repeated though the template is called once. please let me know where am i going wrong.
Thanks
Within the template that matches the para element you are doing this
<xsl:apply-templates/>
This will look at both the child nodes of the para element and select templates that match them. As one of the child elements is content-style this will obviously apply the template that matches it.
However, within the template that matches phrase (which is the other child of para you do this (in the case where the para element has an align attribute, which is does here)
<xsl:apply-templates select="following-sibling::node()[1]"/>
The following sibling is the content-style, and so this will also use the template. Thus the template matching content-style gets called twice.
One solution is to the template matching para so that instead of doing <xsl:apply-templates/>, it explicitly ignores nodes that following phrase elements
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
Try this template for para instead
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align=center and ./#differentiation">
<div class="para align-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align=center and not(./#differentiation)">
<div class="para align1-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align and ./phrase[1]">
<div class="para new">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I have the following XSLT:
<xsl:template match="/">
<div id="dokumentliste">
<xsl:variable name="alleNyheder" select="$currentPage//node" />
<xsl:for-each select="$alleNyheder">
<xsl:sort data-type="text" select="#createDate" order="descending" />
<xsl:if test="./data[#alias='manchet'] != ''">
<div class="newsitem">
<h2>
<xsl:value-of select="./data[#alias='title']"/>
</h2>
<xsl:if test="./data[#alias = 'manchet'] != ''">
<div class="nyhedContent">
<p>
<span class="dokumentListeDato">
<xsl:choose>
<xsl:when test="./data[#alias='date'] != ''">
<xsl:value-of select="umbraco.library:FormatDateTime(./data[#alias='date'], 'dd. MMMM yyyy')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:FormatDateTime(./#createDate, 'dd. MMMM yyyy')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:value-of select="./data[#alias = 'manchet']"/>
</p>
</div>
</xsl:if>
<div class="dokumentListe_laes_mere">
<a href="{umbraco.library:NiceUrl(#id)}">
Læs mere<img src="/frontend/images/macro/macro_laes_mere.png" alt="Læs mere"/>
</a>
</div>
</div>
<!-- End newsitem -->
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
I am making a newslist, and would like to make some sort of pagination. Almost the same one as seen on Google. You know "the usual one".
But I can't figure out how to do this.
The number of newsitems on each page isn't that important, but lets say 10 on each page. When the 10 first newsitems are shown, I would like the pagination to show up. With the "Next" and "Previous" buttons to the right and the left of the numbers.
Is it possible to make this, and have I explained my problem good enough? I use the Umbraco CMS by the way :)
Thank you very much.
-Kim
Something like this:
I've left some code in there for dealing with images in your listing too :-)
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="recordsPerPage" select="2"/>
<xsl:variable name="pageNumber">
<xsl:choose>
<!-- first page -->
<xsl:when test="umbraco.library:RequestQueryString('page') <= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
<!-- what was passed in -->
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>
<!-- The fun starts here -->
<xsl:call-template name="pagination">
<xsl:with-param name="pageNumber" select="$pageNumber"/>
<xsl:with-param name="recordsPerPage" select="$recordsPerPage" />
<xsl:with-param name="numberOfRecords" select="$numberOfRecords" />
</xsl:call-template>
<ul class="listing self-clear">
<xsl:for-each select="$currentPage/node [string(data [#alias='umbracoNaviHide']) != '1']">
<xsl:sort order="descending" select="data[#alias='releasedOn']"></xsl:sort>
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and position() <= number($recordsPerPage * number($pageNumber) + $recordsPerPage )">
<li>
<xsl:attribute name="class">
<xsl:if test="data[#alias='image'] = ''">
no-img
</xsl:if>
<xsl:if test="position() = $recordsPerPage * (number($pageNumber) + 1)">
last
</xsl:if>
</xsl:attribute>
<h3>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName"/>
</a>
</h3>
<xsl:if test="data[#alias='image'] != ''">
<img src="{data[#alias='image']}" class="drop-shadow" />
</xsl:if>
<p class="date"><xsl:value-of select="umbraco.library:LongDate(data[#alias='releasedOn'])"/></p>
<xsl:value-of select="data[#alias='abstract']" disable-output-escaping="yes"/>
Read More
</li>
</xsl:if>
</xsl:for-each>
</ul>
<xsl:call-template name="pagination">
<xsl:with-param name="pageNumber" select="$pageNumber"/>
<xsl:with-param name="recordsPerPage" select="$recordsPerPage" />
<xsl:with-param name="numberOfRecords" select="$numberOfRecords" />
</xsl:call-template>
</xsl:template>
<xsl:template name="pagination">
<xsl:param name="pageNumber"/>
<xsl:param name="recordsPerPage"/>
<xsl:param name="numberOfRecords"/>
<div class="pagination">
<div class="wrapper">
<xsl:if test="(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)">
Next
</xsl:if>
<xsl:if test="$pageNumber > 0">
Prev
</xsl:if>
<span class="page-nos">
Page
<xsl:call-template name="for.loop">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
<xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
</xsl:call-template>
</span>
</div>
</div>
</xsl:template>
<xsl:template name="for.loop">
<xsl:param name="i"/>
<xsl:param name="count"/>
<xsl:param name="page"/>
<xsl:if test="$i <= $count">
<span>
<xsl:if test="$page != $i">
<a href="{umbraco.library:NiceUrl($currentPage/#id)}?page={$i - 1}" >
<xsl:value-of select="$i" />
</a>
</xsl:if>
<xsl:if test="$page = $i">
<xsl:value-of select="$i" />
</xsl:if>
</span>
</xsl:if>
<xsl:if test="$i <= $count">
<xsl:call-template name="for.loop">
<xsl:with-param name="i">
<xsl:value-of select="$i + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
<xsl:with-param name="page">
<xsl:value-of select="$page"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
I figured this one out now. I can see that you have just copy/pasted the pagination that where made by Tim Geyssens here: http://www.nibble.be/?p=11
And the code is also kind'a good, but I changed some of it to get it working. I don't know if I should just accept my own answer as the right one, the answer from Myster as the right one or if I can delete this post?