improve logic of extraction and combination
This commit is contained in:
parent
0d4285a717
commit
3ece269932
36
fsfe.xsl
36
fsfe.xsl
@ -18,16 +18,16 @@
|
||||
<xsl:if test="/buildinfo/document/@external">https://fsfe.org</xsl:if>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- EXTRACT -->
|
||||
<!-- EXTRACT / DESCRIPTION of each page -->
|
||||
<xsl:variable name="metadesc">
|
||||
<!-- Get the meta element description -->
|
||||
<xsl:value-of select="/buildinfo/document/head/meta[@name = 'description']/@content" />
|
||||
</xsl:variable>
|
||||
|
||||
<!-- if there is a meta description, take that -->
|
||||
<!-- if there is a meta description, take that as an extract -->
|
||||
<xsl:variable name="extract">
|
||||
<xsl:choose>
|
||||
<!-- if there is a meta description, take that -->
|
||||
<!-- case 1: if there is a meta description, take that -->
|
||||
<xsl:when test="$metadesc != ''">
|
||||
<xsl:value-of select="$metadesc" />
|
||||
</xsl:when>
|
||||
@ -35,37 +35,31 @@
|
||||
<!-- take a first extract which should be sufficient for most pages -->
|
||||
<xsl:variable name="extract1">
|
||||
<!-- retrieve the first 200 letters of the first p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[1]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure first extract length -->
|
||||
<xsl:variable name="extractlength1">
|
||||
<xsl:value-of select="string-length($extract1)" />
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[1]),1,155)" />
|
||||
</xsl:variable>
|
||||
<!-- define cases what happens with which extract length -->
|
||||
<xsl:choose>
|
||||
<!-- case: first extract is long enough -->
|
||||
<xsl:when test="$extractlength1 > 50">
|
||||
<!-- case 2: first paragraph is long enough -->
|
||||
<xsl:when test="string-length($extract1) > 50">
|
||||
<xsl:value-of select="$extract1" />
|
||||
<xsl:text>...</xsl:text>
|
||||
</xsl:when>
|
||||
<!-- case: first extract is too short -->
|
||||
<!-- case 3: first paragraph is too short -->
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="extract2">
|
||||
<!-- retrieve the first 200 letters of the *second* p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[2]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure *second* extract length -->
|
||||
<xsl:variable name="extractlength2">
|
||||
<xsl:value-of select="string-length($extract2)" />
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[2]),1,155)" />
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<!-- case: second extract is long enough -->
|
||||
<xsl:when test="$extractlength2 > 50">
|
||||
<xsl:value-of select="$extract2" />
|
||||
<!-- case 3a: second paragraph is long enough -->
|
||||
<xsl:when test="string-length($extract2) > 50">
|
||||
<!-- Combine $extract1 and $extract2 with max. 155 characters -->
|
||||
<xsl:value-of select="substring(normalize-space(concat($extract1, ' ', $extract2)),1,155)" />
|
||||
<xsl:text>...</xsl:text>
|
||||
</xsl:when>
|
||||
<!-- case: second extract is too short, so take default text -->
|
||||
<!-- case 3b: also second extract is too short, so take a default text -->
|
||||
<xsl:otherwise>
|
||||
Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.
|
||||
<xsl:text>Free Software Foundation Europe is a charity that empowers users to control technology. We enable people to use, understand, adapt and share software.</xsl:text>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
|
Loading…
Reference in New Issue
Block a user